杭电ACM1004,我的答案怎么不对啊
#include<iostream>#include<fstream>#include<string>#include<map>usingnamespacestd;int...
#include<iostream>
#include<fstream>
#include<string>
#include<map>
using namespace std;
int main(int argc,string * argv[])
{
ifstream cin("aaa.txt");
map<string,int> m;
int n;
int i;
string s;
map<string,int>::iterator it,it2;
while(cin>>n)
{
if(n==0) break;
m.clear();
for(i=0;i<n;++i)
{
cin>>s;
if(m.find(s)!=m.end())//在映照容器中查找键值
m[s]=m[s]+1;
else m[s]=1;
}
it2=m.begin();
for(it=m.begin();it!=m.end();it++)
{
if(it2->second<it->second)
it2=it;
}
cout<<it2->first<<endl;
}
return 0;
} 展开
#include<fstream>
#include<string>
#include<map>
using namespace std;
int main(int argc,string * argv[])
{
ifstream cin("aaa.txt");
map<string,int> m;
int n;
int i;
string s;
map<string,int>::iterator it,it2;
while(cin>>n)
{
if(n==0) break;
m.clear();
for(i=0;i<n;++i)
{
cin>>s;
if(m.find(s)!=m.end())//在映照容器中查找键值
m[s]=m[s]+1;
else m[s]=1;
}
it2=m.begin();
for(it=m.begin();it!=m.end();it++)
{
if(it2->second<it->second)
it2=it;
}
cout<<it2->first<<endl;
}
return 0;
} 展开
1个回答
展开全部
不知道为什么你的没通过,我的改成这样就可以了。
#include<iostream>
#include<fstream>
#include<string>
#include<map>
using namespace std;
int main(int argc, char * argv[]){
map<string, int> m;
int n;
int i;
string s;
map<string, int>::iterator it, it2;
while(cin >> n){
if(n == 0) break;
m.clear();
for(i = 0; i < n; ++i){
cin >> s;
if(m.find(s) != m.end())//在映照容器中查找键值
m[s] = m[s] + 1;
else m[s] = 1;
}
it2 = m.begin();
for(it = m.begin(); it != m.end(); it++){
if(it2->second < it->second)
it2 = it;
}
cout << it2->first << endl;
}
return 0;
}
#include<iostream>
#include<fstream>
#include<string>
#include<map>
using namespace std;
int main(int argc, char * argv[]){
map<string, int> m;
int n;
int i;
string s;
map<string, int>::iterator it, it2;
while(cin >> n){
if(n == 0) break;
m.clear();
for(i = 0; i < n; ++i){
cin >> s;
if(m.find(s) != m.end())//在映照容器中查找键值
m[s] = m[s] + 1;
else m[s] = 1;
}
it2 = m.begin();
for(it = m.begin(); it != m.end(); it++){
if(it2->second < it->second)
it2 = it;
}
cout << it2->first << endl;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询