UVa 755 487--3279

UVa 755 487--3279
注意输出空格时不能使用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 ;
}

你可能感兴趣的:(UVa 755 487--3279)