huicpc0838

hdu1004 let the balloon rise

很水的一个题目,甚至开始我的代码是错的都能过。题目先用hash过掉了,然后在学者用了一下map,stl这个暑假要学一下,真的好有用。

#include<iostream>
#include
<string>
#include
<map>

using namespace std;

int main(){
    map
<stringint> m;
    
int indexx = 0, i, cnt[1001], n, max, temp, ti;
    
char ch[20], save[1001][20];
    
    
while(scanf("%d",&n), n != 0){
        m.clear();indexx
=0;
        
        
for(i=0; i<n; i++){
            scanf(
"%s",ch);
            temp 
= m[ch];
            
if(temp == 0){
            
//    temp = indexx++;
                temp = ++indexx;
                m[ch] 
= temp;
                strcpy(save[temp], ch);
            }

            cnt[temp]
++;
        }

        
        max 
= -1;
        
        
for(i=1; i<=indexx; i++)
            
if(max < cnt[i]){
                max 
= cnt[i];
                ti 
= i;
            }

            
        printf(
"%s\n",save[ti]);
        memset(cnt, 
0sizeof(cnt));        
    }

    system(
"pause");
    
return 0;
}

            
    
开始错误的写法是注释掉的那种,那样有错误我觉得。indexx的作用就像trie里面或者是静态邻接表里面的作用一样。#include<string.h>会ce,不知为何。

posted on 2010-07-13 10:53 huicpc0838 阅读(183) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理


导航

<2026年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

统计

常用链接

留言簿

文章档案

搜索

最新评论