zoukankan      html  css  js  c++  java
  • 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
    ",str);
        }
        return 0;
    }

    先暂时这样吧,后续再继续学习。。

    Everything will be ok in the end. If it is not ok then it is not the end.
  • 相关阅读:
    冲刺 09
    冲刺08
    个人作业-买书
    冲刺07
    冲刺 06
    软件工程 寻找小水王
    冲刺04
    冲刺 03
    冲刺 02
    冲刺3
  • 原文地址:https://www.cnblogs.com/shirleytian/p/3197725.html
Copyright © 2011-2022 走看看