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

终于AC了,STL,有点慢922MS

Posted by absolute at 2009-03-18 12:10:38 on Problem 1002
#include <iostream>
#include <map>
#include <string>
using namespace std;
char change[] = {'2','2','2','3','3','3','4','4','4',
'5','5','5','6','6','6','7','Q','7','7','8','8','8','9','9','9','Z'};

int main()
{
 map<string,int> resultset;
 map<string,int>::iterator iter;
 int line;
 scanf("%d",&line);
 int i;
 for(i=0;i<line;i++)
 {
  char temp[100];
  scanf("%s",temp);
  char afterchange[9];
  int j=0,k=0;
  int length = strlen(temp);
  while(j<length)
  {
   if(k==3)
   {
    afterchange[k++]='-';
   }
   else if(temp[j]<'Z'&&temp[j]>='A')
   {
    afterchange[k++]=change[temp[j++]-'A'];
   }
   else if(temp[j]=='-')
   {
    j++;
   }
   else
   {
    afterchange[k++]=temp[j++];
   }

  }
  afterchange[k]='\0';
  ++resultset[afterchange];
 }
 bool flag = false;
 map<string,int>::iterator end = resultset.end();
 for(iter = resultset.begin(); iter != end; ++iter)
 {
  if(iter->second>1)
  {
   flag = true;
   cout<<iter->first<<" "<<iter->second<<endl;
  }
 }
 if(flag==false)
  cout<<"No duplicates."<<endl;
 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