UVa 755 - 487--3279

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

中文網址

Solution

直接用 std::map<string,int> 來記次數,最後跑一次即可。

Code

UVa 755
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<cstdio>
#include<map>
#include<string>
#include<cctype>
using namespace std;

int main()
{
const char alp[27] = { "22233344455566670778889990" };
int Case;
scanf("%d", &Case);
while (Case--)
{
int n, i;
char c, num[9];
map<string, int> M;

scanf("%d", &n);
getchar();
for (i = 0; i < n; i++)
{
int idx = 0;
while ((c = getchar()) != '\n')
{
if (isdigit(c))
num[idx++] = c;
else if (isalpha(c) && c != 'Q'&&c != 'Z')
num[idx++] = alp[c - 'A'];
if (idx == 3)
num[idx++] = '-';
}

num[idx] = NULL;
M[string(num)]++;
}

bool no = true;
for (map<string, int>::iterator it = M.begin(); it != M.end(); it++)
{
if (it->second > 1)
{
if (no)
no = false;

printf("%s %d\n", it->first.c_str(), it->second);
}
}

if (no)
puts("No duplicates.");

if (Case)
putchar('\n');
}

return 0;
}