Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 198447 | Accepted: 34554 |
Description
Input
Output
Sample Input
12 4873279 ITS-EASY 888-4567 3-10-10-10 888-GLOP TUT-GLOP 967-11-11 310-GINO F101010 888-1200 -4-8-7-3-2-7-9- 487-3279
Sample Output
310-1010 2 487-3279 4 888-4567 3
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <map> using namespace std; char convert(char c){ if(c <= 'C') return '2'; else if(c <= 'F') return '3'; else if(c <= 'I') return '4'; else if(c <= 'L') return '5'; else if(c <= 'O') return '6'; else if(c <= 'S') return '7'; else if(c <= 'V') return '8'; else if(c <= 'Y') return '9'; } int main() { int N; bool flag = false; cin >> N; map<string,int> telp_count; while(N--){ string s,res; cin >> s; int i = 0; for(string::iterator s_it = s.begin();s_it != s.end();++s_it){ if(*s_it >= '0' && *s_it <= '9') res.push_back(*s_it); if(*s_it >= 'A' && *s_it <= 'Z') res.push_back(convert(*s_it)); } res.insert(3,1,'-'); ++telp_count[res]; } map<string,int>::iterator map_it = telp_count.begin(); for(;map_it != telp_count.end();++map_it) if(map_it->second >= 2){ flag = true; cout << map_it->first << " " << map_it->second << endl; } if(!flag) cout << "No duplicates." << endl; return 0; }
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> //#include <windows.h> char convert(char c) { if(isdigit(c)) return c; else if(c <= 'C') return '2'; else if(c <= 'F') return '3'; else if(c <= 'I') return '4'; else if(c <= 'L') return '5'; else if(c <= 'O') return '6'; else if(c <= 'S') return '7'; else if(c <= 'V') return '8'; else if(c <= 'Y') return '9'; } int compar(const void *a, const void *b) { long *aa = (long *)a,*bb = (long *)b; return (*aa > *bb) ? 1 : (*aa == *bb ? 0 : -1); } int main(void) { long n,*res,counter = 0 ,duplicate = 0; int i = 0 , j = 0,k = 0; char s[16],c; scanf("%ld",&n); res = (long *)malloc(sizeof(long)*n); while(j < n) { scanf("%s",s); for(i = k = 0;s[i]!='\0';i++) { if(s[i] == '-') continue; else s[k++] = convert(s[i]); } s[k] = '\0'; res[j++] = atol(s); } qsort(res,n,sizeof(long),compar); counter = 1; for(i = 1; i < n; i++) { if(res[i-1] == res[i]) { counter++; if(i == n-1 && counter > 1) { printf("%0.3ld-%0.4ld %ld\n",res[i-1]/10000,res[i-1]%10000,counter); duplicate++; break; } } else if(res[i-1] != res[i]) { if(counter >= 2) { printf("%0.3ld-%0.4ld %ld\n",res[i-1]/10000,res[i-1]%10000,counter); duplicate++; } counter = 1; } } if(duplicate == 0) printf("No duplicates.\n"); //system("pause"); return 0; }