HDU 1004 map小试
今天做1004,因为之前没用过map,加上很少用C++, 因为又去翻看map的使用,但是依然不是很会,以下代码有借鉴成分
#include <stdio.h> #include <string> #include <iostream> #include <map> using namespace std; //struct Color{ // int time ; //出现次数 // char color[16] ; //}; int main(){ int num; int i; while ((scanf("%d", &num) != EOF)&&(num != 0)){ map<string,int> s; string str; char instring[1001]; for(i = 1; i <= num ; i++){ scanf("%s",instring) ; s[instring]++ ; } int max = 0; for(map<string , int>::iterator it = s.begin(); it!=s.end(); it++){ if(it->second >max){ max = it->second ; str = it->first ; } } cout<<str<<endl; //getchar(); //printf("%s\n",str); } return 0; }
先暂时这样吧,后续再继续学习。。
Everything will be ok in the end. If it is not ok then it is not the end.