| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这个也超时?#include<iostream>
#include<string.h>
#include<math.h>
#include<stdlib.h>
using namespace std;
#define max 100010
char str[max][200];
char ch[max][8];
int compare(const void * a,const void * b)
{
return strcmp((char*)(a),(char*)(b));
}
int main()
{
int n,i=0,j=0,count=0;
cin>>n;
while(n--)
{
cin>>str[i];
j=0;
char *p=str[i];
while(*p!='\0')
{ if(*p>='0'&&*p<='9')
ch[i][j++]=*p;
else if(*p>='A'&&*p<='C')
ch[i][j++]='2';
else if(*p>='D'&&*p<='F')
ch[i][j++]='3';
else if(*p>='G'&&*p<='I')
ch[i][j++]='4';
else if(*p>='J'&&*p<='L')
ch[i][j++]='5';
else if(*p>='M'&&*p<='O')
ch[i][j++]='6';
else if(*p>='P'&&*p<='S'&&*p!='Q')
ch[i][j++]='7';
else if(*p>='T'&*p<='V')
ch[i][j++]='8';
else if(*p>='W'&*p<='Y')
ch[i][j++]='9';
p++;
}
ch[i][j]='\0';
i++;
}
qsort(ch,i-1,8,compare);
for(int k=0;k<i-1;k++)
{
count=0;
if(ch[k][0]!='Q')
{
for(int l=k+1;l<i;l++)
{
if(strcmp(ch[k],ch[l])==0)
{count++;ch[l][0]='Q';}
}
if(count>0)
{
cout<<ch[k][0]<<ch[k][1]<<ch[k][2];
cout<<"-";
cout<<ch[k][3]<<ch[k][4]<<ch[k][5]<<ch[k][6];
cout<<" "<<count+1<<endl;
}
}//getchar();
}
getchar();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator