码迷,mamicode.com
首页 > 其他好文 > 详细

hdu1003 统计出现最多的颜色数(map容器☆☆☆☆☆)

时间:2014-07-26 01:52:36      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:blog   color   os   io   for   re   c   div   

很简单的一道题,利用map容器本应该直接就过的,居然WA了好多次。

后来才发现,丢了一条更新统计结果的语句,以此为戒,以后严加注意!!!

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <string>

using namespace std;

int main(){

    int n;
    map<string,int> countMap;
    string word, tmp;
    char color[32];
    int maxCount;

    while(scanf("%d",&n)&&n){
        maxCount = 0;
        for(int i=0;i<n;i++){
            scanf("%s",color);
            tmp = color;
            if(countMap.find(tmp)==countMap.end()){
                countMap[tmp]=1;
            }
            else{
                countMap[tmp]++;
            }

            if(countMap[tmp]>maxCount){
                word = tmp;
                maxCount = countMap[tmp];
            }
        }

        printf("%s\n",word.c_str());
        countMap.clear();

    }

    return 0;
}

  

hdu1003 统计出现最多的颜色数(map容器☆☆☆☆☆),布布扣,bubuko.com

hdu1003 统计出现最多的颜色数(map容器☆☆☆☆☆)

标签:blog   color   os   io   for   re   c   div   

原文地址:http://www.cnblogs.com/baipengchao/p/3869174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!