Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
已知数据全过,讨论里的问题也都注意了。还是WA。求指导。先谢谢了。 下面是代码。 #include <iostream> using namespace std; struct Node { int number; Node* next; }; int directory[26] = {2,2,2,3,3,3, 4,4,4,5,5,5, 6,6,6,7,-1,7,7, 8,8,8,9,9,9,-1}; int cmp(const void *a, const void *b) { return *(int *)a-*(int *)b; } int transform(char* c_num) { int num[7]; int c_index = 0; int num_index = 0; int dir_index = 0; int number = 0; int power = 1; while (c_num[c_index] != '\0') { if (c_num[c_index] >= '0' && c_num[c_index] <= '9') { num[num_index++] = c_num[c_index] - '0'; } else if (c_num[c_index] == '-' || c_num[c_index]=='Q' || c_num[c_index]=='Z') { } else if (c_num[c_index] >= 'A' && c_num[c_index] <= 'Z') { dir_index = c_num[c_index] - 'A'; num[num_index++] = directory[dir_index]; } else { return -1; } c_index++; } for (int j = 6; j >= 0; j--) { number += num[j] * power; power *= 10; } return number; } int main() { int n; int flag = 0; char c_num[200]; Node* heads[1000]; int count[10000] = {0}; for (int i = 0; i < 1000; i++) { heads[i] = NULL; } cin >> n; for (int i = 0; i < n; i++) { cin >> c_num; int number = transform(c_num); int upper = number / 10000; int below = number % 10000; Node* node = new Node(); node->number = below; node->next = heads[upper]; heads[upper] = node; } cout.fill('0'); for (int i = 0; i < 1000; i++) { Node* cur_node = heads[i]; while (cur_node != NULL) { count[cur_node->number]++; cur_node = cur_node->next; } for (int j = 0; j < 10000; j++) { if (count[j] > 1) { flag = 1; cout.width(3); cout << i << "-"; cout.width(4); cout << j << " " << count[j] << endl; count[j] = 0; } } } if (flag == 0) { cout << "No duplicates." << endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator