| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:给几个数据给大家。借鉴In Reply To:Re:给几个数据给大家。借鉴 Posted by:0815093 at 2010-01-28 21:57:31 > 没有炫耀的意思,我是来盖楼滴!
> #include <iostream>
> #include <string>
> #include <vector>
> #include <algorithm> // STL sort function
> using namespace std;
>
> char map[] = "2223334445556667#77888999#";
> //ABCDEFGHIJKLMNOPQRSTUVWXYZ
> void visited(char &ch) // visit and format strings
> {
> if (ch >= 'A' && ch <= 'Z')
> ch=map[ch-'A']; // ch equals to its real number
> }
>
> int main()
> {
> int N,i=0,j,flag=0;
> string s;
> vector<string> stored(100000); // be visited & stored (up to 100,000)
> cin>>N;
> vector<int> counter(N,1); // stored times
>
> for (; i<N; i++)
> {
> cin>>s;
> for (j=0; j<s.length(); j++) // MSDN
> {
> visited(s[j]);
> if (s[j]!='-')
> {
> stored[i] += s[j];
> if (stored[i].length()==3)
> stored[i] += '-'; // 487 -[3] 3279
> }
> }
> }
> sort(stored.begin(),stored.begin()+N); // Quicker than QuickSort!
> // should not used stored.end() !
> i=0; j=1;
> while (i<N)
> {
> while(stored[i] == stored[j])
> {
> counter[i]++;
> j++;
> flag=1;
> }
> i=j;
> j++;
> }
>
> if (flag)
> for (i=0; i<N; i++)
> {
> if (counter[i]>1)
> cout<<stored[i]<<" "<<counter[i]<<endl;
> } // must have { }
> else cout<<"No duplicates."<<endl;
>
> return 0;
> }
多谢 不过我还是没看出来自己的哪里有错误。。。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator