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

帮忙看看吧 总是tle

Posted by phantomr at 2005-04-24 18:19:53 on Problem 1002
#include<stdio.h>

void swap(char a[],char b[])
{
    char c[9];
    strcpy(c,a);
    strcpy(a,b);
    strcpy(b,c);
    c[8]=a[8];
    a[8]=b[8];
    b[8]=c[8];
}

     
void trans(char a[])
{
    int i;
    for(i=0;i<8;i++)
    if(a[i]>='0'&&a[i]<='9');
    else
       switch(a[i])
      { case 'A':
        case 'B':
        case 'C': a[i]='2';break;
        case 'D':
        case 'E':
        case 'F': a[i]='3';break;
        case 'G':
        case 'H':
        case 'I': a[i]='4';break;
        case 'J': 
        case 'K':
        case 'L': a[i]='5';break;
        case 'M':
        case 'N':
        case 'O': a[i]='6';break;
        case 'P':
        case 'R':
        case 'S': a[i]='7';break;
        case 'T':
        case 'U': 
        case 'V': a[i]='8';break;
        case 'W':
        case 'X':
        case 'Y': a[i]='9';break;
       }
}       
main()
{
    char code[100000][9],c;
    int i,j,n,p=0;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++)
    code[i][8]=1,code[i][7]='\0';
    
    for(i=0,j=0;i<n;)
    {scanf("%c",&c);
     if(c!='-'&&c!='\n')
     {code[i][j]=c;
     j++;
     if(j==7)
     j=0,i++;}}
    
    for(i=0;i<n;i++)
    trans(code[i]);
    
    for(i=1;i<n;i++)
    for(j=0;j<i;j++)
    {if(strcmp(code[i],code[j])==0)
     {code[j][8]++;
      break;}} 
     
    for(j=0;code[j][8]==1;j++);
    do{for(i=j+1;i<n;i++)
       if(code[i][8]>1&&strcmp(code[j],code[i])>0)
       swap(code[j],code[i]);
       for(j=j+1;code[j][8]==1;j++);}
    while(j<n);
    
    for(i=0;i<n;i++)
    if(code[i][8]>1)
    {for(j=0;j<7;j++)
     {printf("%c",code[i][j]);
      if(j==2)
      printf("-");} 
     printf(" %d\n",code[i][8]);
     p=1;}
    if(p==0)
    printf("No duplicates.");
    
   } 

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