Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 1812 | Accepted: 546 |
Description
Input
Input consists of several test cases. The first line of each case contains a single positive integer n. Several lines of text follow which will contain no more than 10000 words. The text for each case is terminated by a single line containing EndOfText. EndOfText does not appear elsewhere in the input and is not considered a word.Output
For each test case, output the words which occur n times in the input text, one word per line, lower case, in alphabetical order. If there are no such words in input, output the following line:There is no such word.Leave a blank line between cases.Sample Input
2In practice, the difference between theory and practice is alwaysgreater than the difference between theory and practice in theory. - AnonymousMan will occasionally stumble over the truth, but most of thetime he will pick himself up and continue on. - W. S. L. ChurchillEndOfTextSample Output
betweendifferenceinwill题目大意:给你一个文本,让你找出出现次数为n的字符串,每个测试数据之间输出一个空行,跟描述基本没有什么关系
。
#include <cstdio>#include <iostream>#include <cstring>#include <sstream>#include <map>using namespace std;map<string,int>a;int main(){ string s,buf; int n,flag=0; while (~scanf("%d",&n)) { if (flag) puts(""); flag++; a.clear(); while (getline(cin,s)&&s!="EndOfText") { for(int i=0; i<s.length(); i++) if (isalpha(s[i])) s[i]=tolower(s[i]); else s[i]=' '; stringstream ss(s);//定义了一个字符串流,并用一个字符串初始化 while (ss>>buf)//将字符串流中的字符串一个个的输出到buf中 { a[buf]++; //cout<<buf<<endl; } } int tt=0; map<string,int>::iterator it; for(it=a.begin(); it!=a.end(); it++) if(it->second==n) { tt=1; cout<<it->first<<endl; } if(!tt) printf("There is no such word./n"); }}
新闻热点
疑难解答