描述 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. 源码分析:静态分析 C 程序函数调用关系图

    http://www.tinylab.org/callgraph-draw-the-calltree-of-c-functions/

  2. Linux文件系统的几个性能测试软件小结

    曾经测试Linux系统下的分布式集群系统的性能,使用了一些测试软件,公司让我给部门同事做一次基础培训,于是翻看以前所写的记录资料挑选了其中几个,所记之处并不完全,只记录使用的功能. 1.Iozone ...

  3. 淘宝Refrash_token签名错误的解决办法

    最近在做淘宝相关应用,想要通过Refrash_token来延长SessionKey的授权时间,但是总是报406 sign error. 经过多次尝试和多方询问,方才知道原来淘宝给的.net SDK里面 ...

  4. .net 后台获取当前请求的设备

    检查当前发起请求的设备是手持设备还是电脑端  以便显示不同的视图 public static bool CheckIsMobile(HttpRequestBase req) { bool flag = ...

  5. find the nth digit

    Problem Description 假设:S1 = 1S2 = 12S3 = 123S4 = 1234.........S9 = 123456789S10 = 1234567891S11 = 12 ...

  6. SQL SERVER – Count Duplicate Records – Rows

    SELECT YourColumn, COUNT(*) TotalCount FROM YourTable GROUP BY YourColumn HAVING COUNT(*) > 1 ORD ...

  7. IOS 给图片添加水印(文字)

    有时候上传图片要加唯一标识,简单的就是添加一个水印.这里水印我们讲文字,可以是当前系统时间.坐标.地理位置等 原理就是把一个字符串写到图片上,并且字(font)的大小由图片大小控制. 以下是封装好的一 ...

  8. Android 高级UI设计笔记20:RecyclerView 的详解之RecyclerView添加Item点击事件

    1. 引言: RecyclerView侧重的是布局的灵活性,虽说可以替代ListView但是连基本的点击事件都没有,这篇文章就来详细讲解如何为RecyclerView的item添加点击事件,顺便复习一 ...

  9. TCP/IP协议原理与应用笔记25:网际协议(IP)之 数据报(Datagram)

    1. 数据报(Datagram)格式: 2. 长度字段 (1)首部长度字段, bits 以 4 字节(即32bits)为单位 取值:5~15(即首部长度为20 ~ 60 bytes) (2)总长度字段 ...

  10. C语言中的命名空间

    C语言中的命名空间 命名空间是为了解决 "在相同作用域内如何区分 相同的标识符". 说明: ①只有在相同作用域的情况下才能使用到命名空间去区分标识符,在嵌套的作用域.不同的作用域区 ...