共有n(n<=20)组数据,其中每组数据有一个正整数m(m<=10),然后是m个单词,统计其中有多少个“sheep”, 单词大小写敏感, 因而"Sheep"等不匹配.
输入描述
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 bufflo ram goat
输出描述
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.
输入样例
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 bufflo ram goat
输出样例
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.
思路:略
通关代码:
#include<iostream>
#define Max 1000
using namespace std;
int main()
{
int forN;//循环次数
cin >> forN;
int n;//数组个数
string str[Max];
int count = 0;
for (int i = 0; i < forN; i++)
{
count = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> str[i];
}
for (int i = 0; i < n; i++)
{
if(str[i] == "sheep")
count++;
}
cout << "Case " << i << ": This list contains " << count << " sheep." << endl;
}
return 0;
}