AOJ-AHU-OJ-31 Counting Sheep

Counting Sheep
Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB
Description
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. Output lines
should be separated by a single blank line.

Sample Input
OriginalTransformed
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
OriginalTransformed
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.

Source
East Central North America 2000 Practise

———————————————————————分割线————————————————————————

思路:极其简单的一个字符串比较函数的应用。

代码如下:
#include <stdio.h>
#include <string.h>
char real[6] = "sheep";
int main(){
	int T, n;
	int i, j = 1;
	scanf("%d", &T);
	while(T--){
		int count = 0;
		scanf("%d", &n);
		char sheep[n][11];
		for(i = 0; i < n; i++)
		  scanf("%s", sheep[i]);
		getchar();
		for( i = 0; i < n; i++){
		  if (strcmp(sheep[i], real) == 0)
		    count++;				
		}
		printf("Case %d: This list contains %d sheep.\n", j++, count);
		if(T != 0)
		putchar('\n');	
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值