hdoj1004 Let the Balloon Rise(map)
2017-06-17 22:06
281 查看
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1004
map的运用
#include<stdio.h>
#include<string>
#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
int judge(string str)
{
map<string,int>::iterator it;
it=m.find(str);
if(it==m.end())return 0;
return 1;
}
int main()
{
int n,count,i,max;
string b;
while(cin>>n&&n)
{
m.clear();
while(n--)
{
cin>>b;
if(judge(b))
{
count=m[b];
m.erase(b);
m[b]=count+1;
}
else
{
m[b]=1;
}
}
max=0;
map<string,int>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
if((it->second)>max)
{
b=it->first;
max=it->second;
}
}
cout<<b<<endl;
}
return 0;
}
map的运用
#include<stdio.h>
#include<string>
#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
int judge(string str)
{
map<string,int>::iterator it;
it=m.find(str);
if(it==m.end())return 0;
return 1;
}
int main()
{
int n,count,i,max;
string b;
while(cin>>n&&n)
{
m.clear();
while(n--)
{
cin>>b;
if(judge(b))
{
count=m[b];
m.erase(b);
m[b]=count+1;
}
else
{
m[b]=1;
}
}
max=0;
map<string,int>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
if((it->second)>max)
{
b=it->first;
max=it->second;
}
}
cout<<b<<endl;
}
return 0;
}
相关文章推荐
- HDOJ 1004 Let the Balloon Rise (map)
- hdoj 1004 Let the Balloon Rise (map)
- hdoj 1004 Let the Balloon Rise(map)
- HDOJ_Problem Archive_1004_Let the Balloon Rise
- HDU 1004 Let the Balloon Rise (map使用)
- hdoj-1004-Let the Balloon Rise(水题)
- HDU-#1004 Let the Balloon Rise(字符串+map)
- HDU-1004 Let the Balloon Rise STL map
- HDOJ&nbsp;1004&nbsp;Let&nbsp;the&nbsp;Balloon&nbsp;Rise
- hdoj-1004-Let the Balloon Rise(水题)
- HDU/HDOJ 1004 Let the Balloon Rise(颜色统计)
- HDOJ 1004 Let the Balloon Rise(字符串)
- HDOJ 1004 Let the Balloon Rise
- HDOJ_1004_Let the Balloon Rise
- ACM--模拟--气球出现次数--HDOJ 1004--Let the Balloon Rise--水
- HDU 1004 Let The Balloon Rise (简单map)
- 渣渣ACM日记——1004-Let the Balloon Rise(HDOJ)
- 【map热手题】HDU 1004—Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- hdoj 1004 Let the Balloon Rise 解题报告