描述 Little A is one member of ACM team. He had just won the gold in World Final. To celebrate, he decided to invite all to have one meal. As bowl, knife and other tableware is not enough in the kitchen, Little A goes to take backup tableware in warehouse. There are many boxes in warehouse, one box contains only one thing, and each box is marked by the name of things inside it. For example, if "basketball" is written on the box, which means the box contains only basketball. With these marks, Little A wants to find out the tableware easily. So, the problem for you is to help him, find out all the tableware from all boxes in the warehouse.

 
输入
There are many test cases. Each case contains one line, and one integer N at the first, N indicates that there are N boxes in the warehouse. Then N strings follow, each string is one name written on the box.
输出
For each test of the input, output all the name of tableware.
样例输入
3 basketball fork chopsticks
2 bowl letter
样例输出
fork chopsticks
bowl

提示

The tableware only contains: bowl, knife, fork and chopsticks.

#include <cstring>
#include <string>
using namespace std;
int main()
{
int n,i;
char a[1010][20];
//char *s1 = "bowl";
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
for (i=0;i<n;i++)
scanf("%s",a[i]);
for (i=0;i<n;i++)
{
if(strcmp(a[i],"bowl") == 0)
printf("bowl ");
if(strcmp(a[i],"knife") == 0)
printf("knife ");
if(strcmp(a[i],"fork") == 0)
printf("fork ");
if(strcmp(a[i],"chopsticks") == 0)
printf("chopsticks ");
}
printf("\n");
}
return 0;
}

同样的正常运行,下面的代码就是提交不正确,

给出这样的提示错误,不能明白这是什么道理,在这里,看似没有使用指针,实际上是在无数的指针在使用着,指针的使用需要严格按照格式,不得出现任何的错误。

运行时出错:
常见出错的原因可能有以下几种:
1、数组开得太小了,导致访问到了不该访问的内存区域
2、发生除零错误
3、大数组定义在函数内,导致程序栈区耗尽
4、指针用错了,导致访问到不该访问的内存区域
5、还有可能是程序抛出了未接收的异常

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
int n,i;
char a[1010][20];
//char *s1 = "bowl";
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
while (n--)
{
scanf("%s",a[i]);
if(strcmp(a[i],"bowl") == 0)
printf("bowl ");
if(strcmp(a[i],"knife") == 0)
printf("knife ");
if(strcmp(a[i],"fork") == 0)
printf("fork ");
if(strcmp(a[i],"chopsticks") == 0)
printf("chopsticks ");
}
printf("\n");
}
return 0;
}

nyoj_t218(Dinner)的更多相关文章

  1. nyoj 218 Dinner(贪心专题)

    Dinner 时间限制:100 ms  |  内存限制:65535 KB 难度:1   描述 Little A is one member of ACM team. He had just won t ...

  2. Codeforces Educational Codeforces Round 5 B. Dinner with Emma 暴力

    B. Dinner with Emma 题目连接: http://www.codeforces.com/contest/616/problem/A Description Jack decides t ...

  3. Codeforces Gym 100342D Problem D. Dinner Problem Dp+高精度

    Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1003 ...

  4. nyoj 218 Dinner

    Dinner 时间限制:100 ms  |  内存限制:65535 KB 难度:1   描述 Little A is one member of ACM team. He had just won t ...

  5. 网络流(最大流)CodeForces 512C:Fox And Dinner

    Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). T ...

  6. UVA - 10249 The Grand Dinner

    Description Problem D The Grand Dinner Input: standard input Output: standard output Time Limit: 15 ...

  7. NBUT 1217 Dinner

    [1217] Dinner 时间限制: 1000 ms 内存限制: 32768 K 问题描写叙述 Little A is one member of ACM team. He had just won ...

  8. nyoj Dinner

    Dinner 时间限制:100 ms  |  内存限制:65535 KB 难度:1   描述 Little A is one member of ACM team. He had just won t ...

  9. Dinner

    问题 : Dinner 时间限制: 1 Sec  内存限制: 32 MB 题目描述 Little A is one member of ACM team. He had just won the go ...

随机推荐

  1. django schema migration

    syncdb 仅仅能初始化table(create),不能自己主动update/delete/drop. 那么south应运而生. south简单使用方法: 安装: pip install South ...

  2. Perl 小知识之多行匹配

    如果想匹配多行文本(即文本中有换行符)中的内容,比如: aaa ... bbb ... 要匹配aaa和bbb之间的内容,我们可以使用 /aaa.*bbb/s 其中/s修饰符可以让.匹配任何字符,包括换 ...

  3. javascript complete, onload

    1.complete 属性可返回浏览器是否已完成对图像的加载 <html> <head> <script type="text/javascript" ...

  4. Linux内存管理原理 与文件读写 图 相当详细

    http://www.cnblogs.com/zhaoyl/p/3695517.html http://www.cnblogs.com/huxiao-tee/p/4657851.html#_label ...

  5. Foxit Reader 插件下载

    http://www.foxitsoftware.com/Secure_PDF_Reader/addons.php#install 百度云:http://pan.baidu.com/s/1i3DSlv ...

  6. linux上一些命令

    ps -ef看看有没有tomcat的进程:也可以用netstat -tnl来看tomcat的端口是否开放

  7. IIS 之 打开/关闭 Internet 信息服务

    由于建立测试网站测试代码,重装电脑后不知道IIS在哪打开.下面以windows7为例介绍,打开IIS管理器的简要步骤. 第一步.查找IIS 1.点击" 开始 "→" 控制 ...

  8. 使用NuGet加载包,发现加载的dll都是最新版,原来少加了参数[-Version]

    使用NuGet获取AutoMapper 发现无法正确加载包,项目版本是3.5,获取的dll版本较高,查资料发现可以通过 “-Version” 指定加载包版本 http://www.mamicode.c ...

  9. Big String 块状数组(或者说平方分割)

    Big String 给一个字符串,长度不超过 106,有两种操作: 1. 在第 i 个字符的前面添加一个字符 ch 2. 查询第 k 个位置是什么字符 操作的总数不超过 2000 如果直接模拟的话, ...

  10. 1.7.3 Relevance-相关性

    1. 相关性 相关性是一个查询响应满足用户搜索信息的一个度(程度). 查询响应的相关性主要依赖于上下文的查询.单个搜索应用程序可以通过用户的不同需求和期望被用来在不同的上下文.例如,气候数据的搜索引擎 ...