思路:用map映射。我的代码用g++TLE,用c++由于没分清cstring和string一直CE。
#include<iostream> #include<cstdio> #include<map> #include<string> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset((a),(b),sizeof(a)) #define MAX(a,b,c) max(a,max(b,c)) map<char,char>mp; map<string,int>Mp; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; mp['A']='2',mp['B']='2',mp['C']='2'; mp['D']='3',mp['E']='3',mp['F']='3'; mp['G']='4',mp['H']='4',mp['I']='4'; mp['J']='5',mp['K']='5',mp['L']='5'; mp['M']='6',mp['N']='6',mp['O']='6'; mp['P']='7',mp['R']='7',mp['S']='7'; mp['T']='8',mp['U']='8',mp['V']='8'; mp['W']='9',mp['X']='9',mp['Y']='9'; cin>>t; while(t--) { string s; cin>>s; string ans; int cnt=0; bool flag=true; for(int i=0;i<s.size();i++) { if(isupper(s[i])) { ans+=mp[s[i]]; cnt++; } else if('0'<=s[i]&&s[i]<='9') { ans+=s[i]; cnt++; } if(cnt==3&&flag) { ans+='-'; flag=false; } } Mp[ans]++; } bool flag=true; map<string,int>::iterator it=Mp.begin(); while(it!=Mp.end()) { if(it->second>1)flag=false,cout<<it->first<<' '<<it->second<<endl; it++; } if(flag)cout<<"No duplicates."<<endl; return 0; }