|
板凳
楼主 |
发表于 2019-3-29 16:17:31
|
只看该作者
- #include <iostream>
- #include <algorithm>
- using namespace std;
- const int mm=110000;
- string s[mm];
- int N,i,c,maxc;
- string t;
- ///非常巧妙 ABCDEFGHIJKLMNOPQRSTUVWXYZ
- char tzb[30]="22233344455566670778889990";
- string init(string tel)
- {
- int l=tel.size();
- string t="";
- char ch;
- for (int i=0; i<=l-1; i++)
- {
- if (tel[i]<='Z' && tel[i]>='A') ch=tzb[tel[i]-'A'];
- else if (tel[i]<='9' && tel[i]>='0') ch=tel[i];
- t=t+ch;
- }
- return t.substr(0,3)+"-"+t.substr(3,4); ///顺便格式化成输出的样子
- }
- int main()
- {
- cin>>N;
- for (int i=1; i<=N; i++)
- {
- cin>>s[i];
- s[i]=init(s[i]);
- }
- sort(s+1,s+N+1); ///排序,这样相同的就在一起了
- ///for (i=1; i<=N; i++) cout<<s[i]<<endl;
- string t=s[1];
- s[N+1]="0"; ///假的岗哨
- c=maxc=1;
- for (int i=2; i<=N+1; i++)
- {
- if (s[i]==t)
- {
- c++;
- if (c>maxc) maxc=c;
- }
- else
- {
- if (c>1)cout<<t<<' '<<c<<endl;
- c=1;
- t=s[i];
- }
- }
- if (maxc==1) cout<<"No duplicates.";
- }
- /*
- 3
- TUT-GLOP
- 3-10-10-10
- 310-1010
- */
复制代码
|
|