Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

直接全转换成数,快排一下就得了。不要保存字符串

Posted by tengshengbo at 2005-08-07 23:31:23 on Problem 1002
In Reply To:请帮我看看哪里有问题, map 投机失败 Posted by:sunmoonstar_love at 2005-08-07 22:49:10
> #include<iostream>
> #include<map>
> #include<string>
> using namespace std;
> char tmp[10000];
> string s="1234567";
> map<string,int> inch;
> map<string,int>::const_iterator iter,begin,end;
> int n,i,len;
> int key[26] = {'2','2','2','3','3','3','4','4','4',
>          '5','5','5','6','6','6','7','7','7','7','8','8','8','9','9','9','9'};
> int main()
> {
>     cin>>n;
>     while(n--)
>     {
>         cin>>tmp;
>         len = 0;
>         for(i=0; tmp[i]!=0; i++)
>             if(tmp[i]<='9'&&tmp[i]>='0')
>                 s[len++] = tmp[i];
>             else
>                 if(tmp[i]<'Z'&&tmp[i]>='A')
>                     s[len++] = key[tmp[i]-'A'];
>         if(inch.find(s)==inch.end())
>             inch[s] = 1;
>         else
>             inch[s] += 1;    
>     }
>     begin = inch.begin();
>     end = inch.end();
>     while(begin!=end)
>     {
>         if(begin->second>1)
>         {   
>             cout<<begin->first[0]<<begin->first[1]<<begin->first[2]<<"-"
>                 <<begin->first[3]<<begin->first[4]<<begin->first[5]<<begin->first[6];
>             cout<<" "<<begin->second<<endl;
>         }    
>         begin++;
>     }
>   //  system("pause");        
>     return 0;
> }  

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator