UVa 755 - 487--3279 Or Poj 1002
2013-07-26 20:38
267 查看
UVa上没法提交这题,就去了Poj, poj上提交要略微修改。
方法一:电话号码转换为数字后排序。
方法2: poj上比方法1快, 思想就是转换为数字后,计数排序
方法一:电话号码转换为数字后排序。
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> using namespace std; const int MAXN = 100004; const int BUFF_SIZE = 30; int A[MAXN]; int vis[MAXN]; int n; char buff[BUFF_SIZE]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int T; //scanf("%d", &T); //while(T--) { scanf("%d\n", &n); int s, k; char c; for(int i=0; i<n; i++) { s = 0; while((c = getchar()) != '\n') { if(c == '-') continue; if(isalpha(c)) { if(c <= 'R') k = (c-'A')/3 + 2; else k = (c-'A'- 1)/3 + 2; } else { k = c - '0'; } s = s*10 + k; } A[i] = s; } sort(A, A+n); A = A[n-1] + 1; vis[0] = 1; int found = 0; for(int i=1; i<=n; i++) { vis[i] = 1; if(A[i] == A[i-1]) { vis[i] += vis[i-1]; } else if(vis[i-1] > 1){ printf("%03d-%04d %d\n", A[i-1]/10000, A[i-1]%10000, vis[i-1]); found = 1; } } if(!found) printf("No duplicates.\n"); //if(T) printf("\n"); //} return 0; }
方法2: poj上比方法1快, 思想就是转换为数字后,计数排序
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm> using namespace std; const int MAXN = 100004; const int MAXM = 10000000; int A[MAXN]; int cnt = 0; int vis[MAXM]; int n; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif scanf("%d\n", &n); int s, k; char c; for(int i=0; i<n; i++) { s = 0; while((c = getchar()) != '\n') { if(c == '-') continue; if(isalpha(c)) { if(c <= 'R') k = (c-'A')/3 + 2; else k = (c-'A'- 1)/3 + 2; } else { k = c - '0'; } s = s*10 + k; } ++vis[s]; if(vis[s] == 2) { A[cnt++] = s; } } if(cnt) { sort(A, A+cnt); for(int i=0; i<cnt; i++) printf("%03d-%04d %d\n", A[i]/10000, A[i]%10000, vis[A[i]]); } else { printf("No duplicates.\n"); } return 0; }
相关文章推荐
- 开篇,UVA 755 && POJ 1002 487--3279 (Trie + DFS / sort)
- POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题
- UVa 755 / POJ 1002 / East Central North America 1999 487--3279 (排序)
- uva 755/poj 1002 487-3279
- UVa 755 / POJ 1002 - 487-3279
- uva 755 poj 1002 487-3279
- UVA755- 487-3279
- UVA 755-487--3279
- uva 755 - 487--3279
- UVA 755 - 487--3279
- UVa 755 - 487--3279
- UVa 755 487-3279
- UVa 755 - 487--3279
- UVa 755 487--3279
- UVA - 755 487--3279
- uva 755 - 487--3279
- UVA 755 487--3279
- UVA 755 (暑假-排序、检索(2)-D-487--3279 )
- Uva 755 - 487--3279
- UVa755 487-3279