解题思路:
题意就是让你找出出现次数最多的气球的颜色
一种方法是建立一个string数组,然后进行排序,然后再来寻找次数最多的那一个
另一种方法就是使用STL里面的map,直接寻找最大数字即可
代码如下:
1 #include<bits/stdc++.h> 2 #define mem(a) memset(a,0,sizeof(a)) 3 #define forn(i,n) for(int i=0;i<n;++i) 4 #define for1(i,n) for(int i=1;i<=n;++i) 5 #define IO std::ios::sync_with_stdio(false); std::cin.tie(0) 6 using namespace std; 7 typedef long long ll; 8 const int maxn=1e5+5; 9 const int mod=10007; 10 const int inf=0x3f3f3f3f; 11 12 int n,m,t,k; 13 map<string,int> balloon; 14 15 16 int main() 17 { 18 IO; 19 while(cin>>n&&n) 20 { 21 balloon.clear(); 22 string str,res; 23 int maxs=0; 24 for1(i,n) 25 { 26 cin>>str; 27 balloon[str]++; 28 if(balloon[str]>maxs) 29 { 30 res=str; 31 maxs=balloon[str]; 32 } 33 34 } 35 cout<<res<<endl; 36 } 37 return 0; 38 }
HDU-1004 Let the Balloon Rise map的基础应用
原文:https://www.cnblogs.com/bethebestone/p/12287798.html