心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
注意输出空格时不能使用ends,否则会WA。就在我对这题感到无比绝望的时候,把ends改成" ",AC。
用map<string,int>很轻松就可以完成该题。
以下是我的代码:
#include<iostream>
#include
<string>
#include
<map>
#include
<algorithm>
#include
<cstdio>
#include
<cctype>
using namespace std;
const char kTable[]="2223334445556667777888999";

int main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/

    
int T;
    cin
>>T;
    
bool first_output(true);
    
while(T--)
    {
        
int n;
        cin
>>n;
        map
<string,int> r;
        
for(int i=1;i<=n;i++)
        {
            
string t;
            cin
>>t;
            t.erase(remove(t.begin(),t.end(),
'-'),t.end());
            
for(int j=0;j<t.size();j++)
                
if(!isdigit(t[j]))
                    t[j]
=kTable[t[j]-'A'];
            t.insert(
3,"-");
            r[t]
++;
        }
        
if(first_output)
            first_output
=false;
        
else
            cout
<<endl;
        
bool found(false);
        
for(map<string,int>::iterator i=r.begin();i!=r.end();i++)
            
if(i->second>1)
            {
                cout
<<i->first<<" "<<i->second<<endl;
                found
=true;
            }
        
if(!found)
            cout
<<"No duplicates."<<endl;
    }

    
return 0;
}
posted on 2011-04-11 23:53 lee1r 阅读(489) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:字符串处理题目分类:排序

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理