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

我快疯了 1002 wa 那位帮帮忙

Posted by shaofeng5000 at 2010-06-05 04:14:47
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define INIT_SIZE 100000
#define TELE_SIZE 40
int main()
{
    long n;
    char *string[INIT_SIZE+1];
    char *result[INIT_SIZE+1];
    char tem[20];
    long i,j,p,q,ki;
    int count[INIT_SIZE+1]={0};
    char ch;
    int len,m=0;
    int key=0,k=-1;
    char low[8]={'0'};
    q=0;
    p=0;

    scanf("%d",&n);
    //电话号码串的输入 
    for(i=1;i<=n;i++)
    {
         fflush(stdin);
         string[i]=(char*)malloc(sizeof(char)*TELE_SIZE);
         gets(string[i]);
         fflush(stdin);
    }
    //电话号码
    for(i=1;i<=n;i++)
    {
          //转化为标准模式
          len=strlen(string[i]);
          for(j=0;j<len;j++)
          {
               ch=string[i][j];
               switch(ch)
               {
                    case 'A':
                    case 'B':
                    case 'C':
                    case '2':
                         {
                            q++;
                            tem[q]='2';
                         }
                         break;
                    case 'D':
                    case 'E':
                    case 'F':
                    case '3':
                         {
                            q++;
                            tem[q]='3';
                         }
                         break;
                    case 'G':
                    case 'H':
                    case 'I':
                    case '4':
                         {
                            q++;
                            tem[q]='4';
                         }
                         break;
                    case 'J':
                    case 'K':
                    case 'L':
                    case '5': 
                         {
                            q++;
                            tem[q]='5';
                         }
                         break;
                    case 'M':
                    case 'N':
                    case 'O':
                    case '6':
                         {
                            q++;
                            tem[q]='6';
                         }
                         break;
                    case 'P':
                    case 'R':
                    case 'S':
                    case '7':
                         {
                            q++;
                            tem[q]='7';
                         }
                         break;
                    case 'T':
                    case 'U':
                    case 'V':
                    case '8':
                         {
                            q++;
                            tem[q]='8';
                         }
                         break;
                    case 'W':
                    case 'X':
                    case 'Y':
                    case '9':
                         {
                            q++;
                            tem[q]='9';
                         }
                         break;
                    case '0':
                         {
                             q++;
                             tem[q]='0';
                         }
                         break;
                    case '1':
                         {
                             q++;
                            tem[q]='1';
                         }
                         break;
                    case '-':
                         {
                             if(q==3)
                             {
                                  q++;
                                  tem[q]='-';
                             }
                         }                    
               }               
          }
          if(tem[4]!='-')
          {
                for(j=8;j>4;j--)
                {
                    tem[j]=tem[j-1];
                }
                tem[4]='-';
                tem[9]='\0';
          }       
          if(p==0)
          {
               result[p]=(char*)malloc(sizeof(char)*TELE_SIZE);                                                 
               strcpy(result[p],&tem[1]);
               count[p]++;
               p++;
          }
          else
          {
              
              for(q=0;q<p;q++)
              {
                  if(!strcmp(result[q],&tem[1]))
                  {                        
                        count[q]++;
                        key=1;
                        break;
                  }
              }
              if(key==0)
              {
                   result[p]=(char*)malloc(sizeof(char)*TELE_SIZE);

                    
                        strcpy(result[p],&tem[1]);
                        count[p]++;
                        p++;  
                }
                  
                 key=0;
              }
           q=0;
          
    } 
    //结果输出
    q=p;
    while(q>0)
    {
       k=k+1;
       while(count[k]<1)
       {
          k++;
       }
       low[0]=result[k][0];
       ki=k;
       for(i=k+1;i<p;i++)
       {
           if(count[i]>1)
           {
              if(result[i][0]<low[0])
              {
                low[0]=result[i][0];
                ki=i;                
              }
              else if(result[i][0]=low[0])
              {
                   j=1;
                   while(result[i][j]==result[ki][j])
                   {
                      j++;
                   }
                   if(result[i][j]<result[ki][j])
                   {
                       ki=i;
                   }
              }
            } 
                 
       }
       if(q>0&&count[ki]!=1)
       {
           printf("%s ",result[ki]);        
           printf("%d\n",count[ki]);
           count[ki]=1;
           m++;
       }
       q--;    
    }
    if(m==0)
    printf("No duplicates.");
     system("pause");
     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