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 ...
随机推荐
- LINUX 数据结构 &算法 网络协议 & 网络编程 多任务编程
http://blog.csdn.net/goodluckwhh/article/category/1303091
- 架构设计:负载均衡层设计方案(7)——LVS + Keepalived + Nginx安装及配置
1.概述 上篇文章<架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/artic ...
- IIS 之 HTTP 错误 500.19(无法访问请求页面,因为该页的相关配置数据无效)
HTTP 错误 500.19- Internal Server Error 错误解决方法,碰到这个问题的原因有很多,大家可以参考下,看属于哪种情况. 刚在本机部署了一个WebService测试,浏览的 ...
- js的2种继承方式详解
js中继承可以分为两种:对象冒充和原型链方式 一.对象冒充包括三种:临时属性方式.call()及apply()方式1.临时属性方式 复制代码代码如下: function Person(name){ ...
- Linux常用命令速查备忘
Linux常用命令速查备忘 PS:备忘而已,详细的命令参数说明自己man 一. 启动,关机,登入,登出相关命令 [login] 登录 [logout] 登出 [exit] 登出 [shutdown ...
- solr英文使用的基本分词器和过滤器配置
solr英文应用的基本分词器和过滤器配置 英文应用分词器和过滤器一般配置顺序 索引(index): 1:空格 WhitespaceTokenizer 2:过滤词(停用词,如:on.of.a.an ...
- 通过cagradientLayer类封装uiimageview动画色度差
#import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger, EcolorDirectionType) { EcolorDirectionUp, / ...
- 结合源码看nginx-1.4.0之nginx异步机制详解
目录 0. 摘要 1. nginx异步设计思想 2. nginx异步设计数据结构 3. nginx异步机制源码解析 4. 一个简单的应用异步例子 5. 小结 6. 参考源码
- GET和POST的主要区别
1.get是从服务器上获取数据,post是向服务器传送数据 2.在客户端上,get通过url提交数据,数据在url上可以看到,post方式,数据放置在HTMLHEADER内提交 3.对于get方式,服 ...
- 6. Android框架和工具之 JSON解析
Android进阶笔记17:3种JSON解析工具(org.json.fastjson.gson)