zoukankan      html  css  js  c++  java
  • Dinner http://acm.nyist.net/JudgeOnline/problem.php?pid=218

     

    Dinner

    时间限制:100 ms  |  内存限制:65535 KB
    难度:1
     
    描述
    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.
    来源
    辽宁省10年省赛
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	int n;
    	while(scanf("%d",&n)!=EOF)
    	{
    			char a[100][20];
    			int i,len;
    			for(i=0;i<n;i++)
    			{
    				getchar();
    				len=1;
    				scanf("%s",a[i]);
    				if(a[i][0]=='b'&&a[i][1]=='o'&&a[i][2]=='w'&&a[i][3]=='l')
    					printf("bowl");
    				else if(a[i][0]=='k'&&a[i][1]=='n'&&a[i][2]=='i'&&a[i][3]=='f'&&a[i][4]=='e')
    					printf("knife");
    				else if(a[i][0]=='f'&&a[i][1]=='o'&&a[i][2]=='r'&&a[i][3]=='k')
    					printf("fork");
    				else if(a[i][0]=='c'&&a[i][1]=='h'&&a[i][2]=='o'&&a[i][3]=='p'&&a[i][4]=='s'&&a[i][5]=='t'&&a[i][6]=='i'&&a[i][7]=='c'&&a[i][8]=='k'&&a[i][9]=='s')
    					printf("chopsticks");
    				else
    					len=0;
    				if(i==n-1)
    					printf("
    ");
    				else if(len!=0)
    					printf(" ");
    			}
    	}
    	return 0;
    }
    

    很好写的一道题,注意输出的空格和换行。还有getchar的位置。

  • 相关阅读:
    Java 装饰者模式
    struts2注解的作用
    XML DOM 笔记
    XMLHttpRequest的用法
    Eclipse中实现JS代码提示功能
    .after()和.before()的关系
    xml的的特殊字符转义&
    html和xml的区别
    dom4j的解析实例
    tld自定义标签系列--使用body-content的作用--比较有用
  • 原文地址:https://www.cnblogs.com/wangyouxuan/p/3267038.html
Copyright © 2011-2022 走看看