Run ID | User | Problem | Result | Memory | Time | Language | Code Length | Submit Time |
6624081 | kingpro | 1002 | Accepted | 940K | 860MS | C++ | 1421B | 2010-03-24 23:28:55 |
![ContractedBlock.gif](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1
#include
<
iostream
>
2 using namespace std;
3
4 struct Telep
5 {
6 char number[ 7 ];
7 };
8
9 char reflect[ 43 ] =
10 {
11 ' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' ,
12 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
13 ' 2 ' , ' 2 ' , ' 2 ' ,
14 ' 3 ' , ' 3 ' , ' 3 ' ,
15 ' 4 ' , ' 4 ' , ' 4 ' ,
16 ' 5 ' , ' 5 ' , ' 5 ' ,
17 ' 6 ' , ' 6 ' , ' 6 ' ,
18 ' 7 ' , 0 , ' 7 ' , ' 7 ' ,
19 ' 8 ' , ' 8 ' , ' 8 ' ,
20 ' 9 ' , ' 9 ' , ' 9 ' , 0
21 };
22
23 int cmp( const void * a, const void * b)
24 {
25 Telep * c = (Telep * )a, * d = (Telep * )b;
26 for ( int i = 0 ; i < 7 ; i ++ )
27 {
28 if (c -> number[i] == d -> number[i])
29 continue ;
30 return c -> number[i] - d -> number[i];
31 }
32 return 0 ;
33 }
34 void print(Telep & t, int cnt)
35 {
36 int i = 0 ;
37 for (; i < 3 && (cout << t.number[i], true ); i ++ );
38 cout << ' - ' ;
39 for (; i < 7 && (cout << t.number[i], true ); i ++ );
40 cout << ' ' << cnt << endl;
41 }
42
43 int main()
44 {
45 int cnt = 0 , i = 0 ;
46 cin >> cnt;
47 Telep * phone = new Telep[cnt];
48 for (i = 0 ; i < cnt; i ++ )
49 {
50 char code[ 20 ] = { 0 };
51 cin >> code;
52 Telep tmp;
53 for ( int j = 0 , k = 0 ; k < 7 && code[j] != 0 && code[j] != ' \0 ' ; j ++ )
54 {
55 if (code[j] == ' - ' )
56 continue ;
57 if (reflect[code[j] - 48 ] != 0 )
58 tmp.number[k ++ ] = reflect[code[j] - 48 ];
59 else
60 break ;
61 }
62 phone[i] = tmp;
63 }
64 qsort(phone, cnt, sizeof (phone[ 0 ]), cmp);
65 int tcnt = 1 , ttcnt = 0 ;
66 for (i = 1 ; i < cnt; i ++ )
67 if ( ! cmp( & phone[i - 1 ], & phone[i]))
68 {
69 tcnt ++ , ttcnt ++ ; continue ;
70 }
71 else
72 tcnt != 1 && (print(phone[i - 1 ], tcnt), tcnt = 1 );
73 tcnt != 1 && (print(phone[i - 1 ], tcnt), true );
74 ttcnt == 0 && cout << " No duplicates. " << endl;
75 return 0 ;
76 }
2 using namespace std;
3
4 struct Telep
5 {
6 char number[ 7 ];
7 };
8
9 char reflect[ 43 ] =
10 {
11 ' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' ,
12 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
13 ' 2 ' , ' 2 ' , ' 2 ' ,
14 ' 3 ' , ' 3 ' , ' 3 ' ,
15 ' 4 ' , ' 4 ' , ' 4 ' ,
16 ' 5 ' , ' 5 ' , ' 5 ' ,
17 ' 6 ' , ' 6 ' , ' 6 ' ,
18 ' 7 ' , 0 , ' 7 ' , ' 7 ' ,
19 ' 8 ' , ' 8 ' , ' 8 ' ,
20 ' 9 ' , ' 9 ' , ' 9 ' , 0
21 };
22
23 int cmp( const void * a, const void * b)
24 {
25 Telep * c = (Telep * )a, * d = (Telep * )b;
26 for ( int i = 0 ; i < 7 ; i ++ )
27 {
28 if (c -> number[i] == d -> number[i])
29 continue ;
30 return c -> number[i] - d -> number[i];
31 }
32 return 0 ;
33 }
34 void print(Telep & t, int cnt)
35 {
36 int i = 0 ;
37 for (; i < 3 && (cout << t.number[i], true ); i ++ );
38 cout << ' - ' ;
39 for (; i < 7 && (cout << t.number[i], true ); i ++ );
40 cout << ' ' << cnt << endl;
41 }
42
43 int main()
44 {
45 int cnt = 0 , i = 0 ;
46 cin >> cnt;
47 Telep * phone = new Telep[cnt];
48 for (i = 0 ; i < cnt; i ++ )
49 {
50 char code[ 20 ] = { 0 };
51 cin >> code;
52 Telep tmp;
53 for ( int j = 0 , k = 0 ; k < 7 && code[j] != 0 && code[j] != ' \0 ' ; j ++ )
54 {
55 if (code[j] == ' - ' )
56 continue ;
57 if (reflect[code[j] - 48 ] != 0 )
58 tmp.number[k ++ ] = reflect[code[j] - 48 ];
59 else
60 break ;
61 }
62 phone[i] = tmp;
63 }
64 qsort(phone, cnt, sizeof (phone[ 0 ]), cmp);
65 int tcnt = 1 , ttcnt = 0 ;
66 for (i = 1 ; i < cnt; i ++ )
67 if ( ! cmp( & phone[i - 1 ], & phone[i]))
68 {
69 tcnt ++ , ttcnt ++ ; continue ;
70 }
71 else
72 tcnt != 1 && (print(phone[i - 1 ], tcnt), tcnt = 1 );
73 tcnt != 1 && (print(phone[i - 1 ], tcnt), true );
74 ttcnt == 0 && cout << " No duplicates. " << endl;
75 return 0 ;
76 }
直接模拟题意即可