ZOJ Problem Set - 1159 487-3279

龙哥刚才做的一道题,水,但是他一直找不到错,我试着改了下交,果然是那个计数一环出错了。

龙哥水题抽筋。

map + sort + string

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
string num[100001];
map <char,char>mymap;

string change( string s )
{
    int i;
    string ns;
    ns="";
    for( i=0;i<s.size();i++ )
    {
        if( s[i]=='-' )
            continue;
        else if(  s[i]>='0' && s[i]<='9' )
        {
            ns+=s[i];
            continue;
        }
        ns+=mymap[ s[i] ];
    }
    return ns;
}

int main()
{
    int T,n,i,j,times,first;
    string s;
    bool nothing;
    //freopen( "a.txt","r",stdin );
    mymap['A']='2'; mymap['B']='2'; mymap['C']='2'; mymap['D']='3';
    mymap['E']='3'; mymap['F']='3'; mymap['G']='4'; mymap['H']='4';
    mymap['I']='4'; mymap['J']='5'; mymap['K']='5'; mymap['L']='5';
    mymap['M']='6'; mymap['N']='6'; mymap['O']='6'; mymap['P']='7';
    mymap['R']='7'; mymap['S']='7'; mymap['T']='8'; mymap['U']='8';
    mymap['V']='8'; mymap['W']='9'; mymap['X']='9'; mymap['Y']='9';
    cin>>T;
    first=1;
    while( T-- )
    {
        cin>>n;
        for( i=0;i<n;i++ )
        {
            cin>>s;
            num[i]=change(s);
        }
        sort( num,num+n );
        if( first!=1 )  cout<<endl;
        nothing=true;
        times = 0;
        num[i] = "###";
        for( i=1;i<=n;i++ )
        {
            if(num[i] == num[i-1])
            {times ++;nothing = false;}
            else
            {
                  if(times > 0)
                  {
                        num[i-1].insert(3,"-");
                        cout<<num[i-1]<<" "<<times +1<<endl;
                  }
                  times = 0;
            }
        }
        if( nothing )   cout<<"No duplicates.\n";
        first++;
    }
    return 0;
}


你可能感兴趣的:(ZOJ Problem Set - 1159 487-3279)