poj 1002 487-3279

纯模拟,STL中map的应用吧。。

这题的数据比较BT,stdio输入输出+map+nlogn的算法都会TLE。。。

恩,在这个连O(n)都会TLE的年代,nlogn神马的都是浮云了,poj连常数都要卡。。。

所以呢,需要在字符串处理那里优化下,把char变成int来比较,具体的就见code吧。。。
#include <iostream>
#include 
<cstdio>
#include 
<cstring>
#include 
<map>

using namespace std;

const int strs[26]= {22233344455566670778889990};

int main()
{
    
int times;
    scanf(
"%d"&times);
    map
<intint> names;
    
while(times--)
    {
        
char str[100];
        
int strnum = 0, i = 0, num= 0;
        scanf(
"%s", str);
        
while ( strnum < 7)
        {
            
while ('-' == str[i])
                i
++;
            
if (str[i] >= 'A' && str[i] < 'Z')
            {
                num
=num*10+strs[str[i]-'A'];
            }
            
else
            {
                num
=num*10+(str[i]-'0');
            }
            i
++;
            strnum
++;
        }
        names[num]
++;
    }
    
int out= 1;
    map
<intint>::iterator point;
    
for ( point = names.begin(); point != names.end(); point++ )
    {
        
if (point->second > 1)
        {
            
out= 0;
            printf(
"%03d-%04d %d\n", point->first/10000, point->first%10000, point->second);
        }
    }
    
if(out)
    {
        printf(
"No duplicates.\n");
    }
    
return 0;
}

posted on 2011-08-05 22:53 purplest 阅读(273) 评论(0)  编辑 收藏 引用 所属分类: STL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年8月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

导航

统计

常用链接

留言簿

随笔分类(70)

随笔档案(68)

ACMer

搜索

最新随笔

最新评论