problem 1159

来源:互联网 发布:日本动漫推荐 知乎 编辑:程序博客网 时间:2024/05/17 01:36
Accepted 1159 C++ 00:03.33 3280K

STL写的,效率超低,不过代码很简单。

#include <stdio.h>
#include 
<string.h>
#include 
<map>
using namespace std;
const int aph[26= {2223334445556667-177888999-1
};
void solve(int
 n)
{
    
int cnt = 0, flag = 0
;
    map
<intint>
 table;
    
for(int i = 0; i < n; i++
)
    {
        
int temp = 0
;
        
char
 c;
        
while(scanf("%c"&c) != EOF && c != ' '
)
            
if(c != '-'
)
                temp 
= (10 * temp + ((c >= 'A' && c <= 'Z'? aph[c - 'A'] : (c - '0'
)));
        table[temp]
++
;
    }
    
for(map<intint>::iterator it = table.begin(); it != table.end(); it++
)
    {
        
int temp = it->
second;
        
if(temp > 1
)
        {
            
int p1 = (it->first) / 10000, p2 = (it->first) % 10000
;
            
if(p1 < 10)    printf("00"
);
            
else if(p1 < 100)    printf("0"
);
            printf(
"%d-"
, p1);
            
if(p2 < 10)    printf("000"
);
            
else if(p2 < 100)    printf("00"
);
            
else if(p2 < 1000)    printf("0"
);
            printf(
"%d %d/n"
, p2, temp);
            flag 
= 1
;//其实很不想用flag的,不爽.
        }
    }
    
if(flag == 0
)
        printf(
"No duplicates./n"
);
}
int
 main()
{
#ifndef ONLINE_JUDGE
    freopen(
"1159.txt""r"
, stdin);
#endif

    
int t, n;
    
while(scanf("%d"&t) !=
 EOF)    
        
for(int i = 0; i < t; i++
)
        {
            
if(i > 0)    printf("/n"
);
            scanf(
"%d/n"&
n);
            solve(n);
        }
#ifndef ONLINE_JUDGE
    fclose(stdin);
#endif

    
return 0;
}
原创粉丝点击