Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 218209 | Accepted: 38038 |
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
Source
Translator
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <ctype.h>
#include <vector>
#include <queue>
#include <set>
using namespace std;
#define MAXN 100010
#define Inf 0x7ffffff
#define eps 1e10-8
#define mod 1000000007
typedef long long LL;
const double PI = acos(-1.0);
typedef double D;
//#define Online_Judge
#define outstars cout << "***********************" << endl;
char s1[320];
bool cmp(const pair<string,int>& a,const pair<string,int>& b){
for (int i=0;i<8;i++){
if (a.first[i]==b.first[i]) continue;
else return a.first[i]<b.first[i];
}
return true;
}
int main()
{
#ifdef Online_Judge
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // Online_Judge
map <string , int> m;
map <string , int> ::iterator itr;
int T;
scanf("%d",&T);
char tran[100];
tran['1']='1';
tran['0']='0';
tran['A']=tran['B']=tran['C']=tran['2']='2';
tran['D']=tran['E']=tran['F']=tran['3']='3';
tran['G']=tran['H']=tran['I']=tran['4']='4';
tran['J']=tran['K']=tran['L']=tran['5']='5';
tran['M']=tran['N']=tran['O']=tran['6']='6';
tran['P']=tran['R']=tran['S']=tran['7']='7';
tran['T']=tran['U']=tran['V']=tran['8']='8';
tran['W']=tran['X']=tran['Y']=tran['9']='9';
while(T--)
{
scanf("%s",s1);
int count = 0;
string s2;
for(int i = 0 ; count < 7 ; i++)
{
if(s1[i] == '-')continue;
s2 += tran[s1[i]];
count ++;
if(count == 3)s2 += '-';
}
if((itr = m.find(s2)) == m.end())
{
m.insert(make_pair(s2 , 1));
}
else (*itr).second++;
}
// int num = 0 ;
// for(map<string, int>::iterator iter = m.begin(); iter != m.end(); ++iter)
// {
// if(m[iter -> first] == 1 )
// {
// num++;
// continue;
// }
// printf("%s %d\n",iter -> first.c_str() , iter -> second);
// }
// if(num == m.size())printf("No duplicates.\n");
vector< pair<string,int> > vec;
for (itr=m.begin();itr!=m.end();itr++){
if (itr->second>1)
vec.insert(vec.end(),*itr);
}
sort(vec.begin(),vec.end(),cmp);
int total=vec.size();
for (int i=0;i<total;i++){
cout<<vec[i].first<<' '<<vec[i].second<<endl;
}
if (vec.size()==0) cout<<"No duplicates."<<endl;
return 0;
}
然后是AC的Hash代码(参照Discuss里的一位神牛的代码)
#include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <map> #include <string> #include <stack> #include <ctype.h> #include <vector> #include <queue> #include <set> using namespace std; #define MAXN 100010 #define Inf 0x7ffffff #define eps 1e10-8 #define mod 1000000007 typedef long long LL; const double PI = acos(-1.0); typedef double D; //#define Online_Judge #define outstars cout << "***********************" << endl; char s[320]; int a[MAXN]; int Hash() { int sum = 0; int count = 0; for(int i = 0 ; count < 7 ; i++) { if(s[i] >= '0'&&s[i] <= '9') { count++; sum *= 10; sum += s[i] - '0'; } else if(s[i] >= 'A'&&s[i] <= 'Z') { sum *= 10; count++; sum += ((s[i] - 'A' - (s[i] > 'Q')) / 3 + 2);///膜拜了,相当于从第三个开始每三个一组为一个hash值,Q,Z不算。。。 } } return sum; } int main() { #ifdef Online_Judge freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif // Online_Judge int T; scanf("%d\n",&T); for(int i =0 ;i < T ; i++) { gets(s); a[i] = Hash(); } sort(a , a + T); bool flag = false; T--; for(int i = 0 , num = 1 ; i < T ; i += num = 1) { while(a[i] == a[i + 1]) { num++; i++; } if(num > 1) { printf("%03d-%04d %d\n",a[i] / 10000 , a[i] % 10000 , num);///一个数分为两部分输出 flag = true; } } if(!flag)printf("No duplicates.\n"); return 0; }