Repository navigation
Expand file tree
/
Copy path1002.cpp
More file actions
107 lines (90 loc) · 1.67 KB
/
Copy path1002.cpp
File metadata and controls
107 lines (90 loc) · 1.67 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <string>
#include <map>
#include <stdio.h>
using namespace std;
typedef std::string::iterator sit;
int GetNum(char c)
{
int n = (int)c;
int n0 = (int)'0';
int n9 = (int)'9';
if( n >= n0 && n <= n9 )
return c - n0;
if( n >= 65 && n < 68)
return 2;//A B C
if( n >= 68 && n < 71)
return 3;//DEF
if( n >= 71 && n < 74)
return 4;// GHI
if( n >= 74 && n < 77)
return 5;//JKL
if( n >= 77 && n < 80)
return 6;//MNO
if(80 == n)
return 7;//P
if( n >= 82 && n < 84)//81-Q 82-R 83-S 84-T
return 7;//RS
if( n >= 84 && n < 87)
return 8;
if( n >= 87 && n < 90)
return 9;
cerr<<"error input";
return 0;
}
int regular(string& s, char z, char* p)
{
int i = 0, j = 0;
int nCount = (int)s.size();
for ( ; i < nCount; ++i)
{
if(z == s[i])
continue;
p[j] = s[i];
++j;
}
return atoi(p);
}
const int LIMIT = 100000;
int main()
{
int nRow = 0;
cin >> nRow;
int i = 0;
if(nRow > LIMIT)
return 0;
string sOne("");
typedef std::map<int, int> mvn;
typedef std::map<int, int>::iterator mvnit;
mvn v_n;
mvnit it;
int nTemp = 0;
char szTemp[9] = {'0'};
for ( ; i < nRow; ++i)
{
cin>>sOne;
nTemp = regular(sOne, '-', szTemp);
it = v_n.find( nTemp );
if( it != v_n.end() )
it->second++;
else
v_n.insert( std::make_pair(nTemp, 1) );
}
bool hasDuplicates = false;
int nPart1(0), nPart2(0);
//char szTemp[9] = {'\0'};
for (mvnit it = v_n.begin(); it != v_n.end(); ++it)
{
if( it->second > 1 )
{
nTemp = it->first;
nPart1 = nTemp/10000;
nPart2 = nTemp%10000;
printf("%03d-%4d", nPart1, nPart2);
hasDuplicates = true;
}
}
if( !hasDuplicates )
cout << "No duplicates." << endl;
return 0;
}