nyoj_t218(Dinner)
描述 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)的更多相关文章
- nyoj 218 Dinner(贪心专题)
Dinner 时间限制:100 ms | 内存限制:65535 KB 难度:1 描述 Little A is one member of ACM team. He had just won t ...
- 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 ...
- Codeforces Gym 100342D Problem D. Dinner Problem Dp+高精度
Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1003 ...
- nyoj 218 Dinner
Dinner 时间限制:100 ms | 内存限制:65535 KB 难度:1 描述 Little A is one member of ACM team. He had just won t ...
- 网络流(最大流)CodeForces 512C:Fox And Dinner
Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). T ...
- UVA - 10249 The Grand Dinner
Description Problem D The Grand Dinner Input: standard input Output: standard output Time Limit: 15 ...
- NBUT 1217 Dinner
[1217] Dinner 时间限制: 1000 ms 内存限制: 32768 K 问题描写叙述 Little A is one member of ACM team. He had just won ...
- nyoj Dinner
Dinner 时间限制:100 ms | 内存限制:65535 KB 难度:1 描述 Little A is one member of ACM team. He had just won t ...
- Dinner
问题 : Dinner 时间限制: 1 Sec 内存限制: 32 MB 题目描述 Little A is one member of ACM team. He had just won the go ...
随机推荐
- python 列表函数(转)
list函数: 功能:将字符创转化为列表,例: 列表基本函数: 1.元素赋值,例: 注意:通过list[0]= 'hel',如果原来位置上有值,会覆盖掉原来的. 2.分片操作 1)显示序列,例: 注意 ...
- 主函数 main WinMain _tmain _tWinMain 的区别
main是C/C++的标准入口函数名 WinMain是windows API窗体程序的入口函数.(int WINAPI WinMain()) 中 WINAPI是__stdcall宏,在windef.h ...
- /proc/sys/vm/ 内存参数
linux下proc里关于磁盘性能的参数 http://blog.csdn.net/eroswang/article/details/6126646 我们在磁盘写操作持续繁忙的服务器上曾经碰到一个特 ...
- CentOS 6.0 图形(图解)安装教程
http://www.cnblogs.com/vipsoft/archive/2012/04/23/2466062.html
- IPC——数据报套接字通信
Linux进程间通信——使用数据报套接字 前一篇文章,Linux进程间通信——使用流套接字介绍了一些有关socket(套接字)的一些基本内容,并讲解了流套接字的使用,这篇文章将会给大家讲讲,数据报套接 ...
- 进程控制之fork函数
一个现有进程可以调用fork函数创建一个新进程. #include <unistd.h> pid_t fork( void ); 返回值:子进程中返回0,父进程中返回子进程ID,出错返回- ...
- vxworks 实时操作系统
VxWorks 是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统.Tornado 是WRS 公司推出的一套实时操作系统开发环境,类似Mi ...
- 关于mysql下hibernate实体类字段与数据库关键字冲突的问题
好久没写了,都忘记博客了,趁着现在还在公司,写的东西是经过验证的,不是在家凭记忆力写的,正确率有保障,就说说最近遇到的一件事情吧. 以前一直用的oracle数据库,这次项目我负责的模块所在的系统是用的 ...
- Linux文件系统的barrier:启用还是禁用
大多数当前流行的Linux文件系统,包括EXT3和EXT4,都将文件系统barrier作为一个增强的安全特性.它保护数据不被写入日记.但 是,在许多情况下,我们并不清楚这些barrier是否有用.本文 ...
- JavaScript对Json的增删改属性
<script type="text/javascript"> var json = { "age":24, "name":&q ...