TJUoj水题 数羊
来源:互联网 发布:ios中网页请求数据 编辑:程序博客网 时间:2024/04/28 01:50
***After a long night of coding, Charles Pearson Peterson is having trouble sleeping. This is not only because he is still thinking about the problem he is working on but also due to drinking too much java during the wee hours. This happens frequently, so Charles has developed a routine to count sheep. Not the animal, but the word. Specifically, he thinks of a list of words, many of which are close in spelling to “sheep”, and then counts how many actually are the word “sheep”. Charles is always careful to be case-sensitive in his matching, so “Sheep” is not a match. You are to write a program that helps Charles count “sheep”.
Input
Input will consist of multiple problem instances. The first line will consist of a single positive integer n ≤ 20, which is the number of problem instances. The input for each problem instance will be on two lines. The first line will consist of a positive integer m ≤ 10 and the second line will consist of m words, separated by a single space and each containing no more than 10 characters.
Output
For each problem instance, you are to produce one line of output in the format:
Case i: This list contains n sheep.
The value of i is the number of the problem instance (we assume we start numbering at 1) and n is the number of times the word “sheep” appears in the list of words for that problem instance. Two successive lines should be separated by a single blank line, but do not output any trailing blank line.
Sample Input
4
5
shep sheeps sheep ship Sheep
7
sheep sheep SHEEP sheep shepe shemp seep
10
sheep sheep sheep sheep sheep sheep sheep sheep sheep sheep
4
shape buffalo ram goat
Sample Output
Case 1: This list contains 1 sheep.
Case 2: This list contains 3 sheep.
Case 3: This list contains 10 sheep.
Case 4: This list contains 0 sheep.
题意:计算与sheep相同的单词个数。
注意:每个样例之间输出一个空行
#include<stdio.h>#include<string.h>#define N 100char str[N];int main(){ int t; int i,count,n,k; scanf("%d",&t); k = t; while( t --) { scanf("%d",&n); count = 0; memset(str,0,sizeof(str)); for( i =1; i <= n; i ++) { scanf("%s",str); if(!strcmp(str,"sheep")) count ++; } if(t!=0) printf("Case %d: This list contains %d sheep.\n\n",k-t,count); else printf("Case %d: This list contains %d sheep.\n",k-t,count); } return 0;}
后记:纪念性的水题,省赛完后第一道刷的题,也是第一次在tjuoj上刷的题。以后好好刷题吧,争取今后超过隔壁大佬
- TJUoj水题 数羊
- 2.19.8 数羊
- 水题,求进位数
- 水题 删数问题
- HDU2097 Sky数【水题】
- 水题,蛇形填数
- 数塔(dp水题)
- 统计单词数(水题)
- 数
- 数
- 数
- 数
- 数
- 数
- hdoj2084 数塔 (DP水题)
- HDU 2040--亲和数【水题】
- HDU2084 数塔 DP水题
- 【水题】hdoj1282回文数猜想
- Jenkins获取git提交记录并上传fir.im
- 欢迎使用CSDN-markdown编辑器
- 报销审批流程
- 搜索——H——找n的倍数(0,1组成的)
- Maven实战(五)坐标详解
- TJUoj水题 数羊
- C# 无窗口的DOS进程操作
- Maven实战(六)依赖
- 单点配置文档
- directive的传值问题(全面解析directive的传值问题)微信分享实例
- SQL Server连接错误代码:18452
- 03-树2 List Leaves (25分)
- 操作系统--动态高优先权算法的Java实现
- JS的Ajax与后端交互数据