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

Re:pku2934 why wrong answer

Posted by RealBC_dccmx at 2007-08-07 17:27:34 on Problem 2934
In Reply To:pku2934 why wrong answer Posted by:ync at 2006-08-06 17:27:18
> #include<stdio.h>
> #include<string.h>
> #include<stdlib.h>
> char word[10005][30];
> int N,len[10005];
> /*
> int sort(const void *a,const void *b)
> {  
>     char *x,*y;
>     x=(char *)a; y=(char *)b;
>     return strcmp(x,y);
> }
> int find(char *st)
> {
>    int i,k,x,x1,x2;
>    x1=1; x2=N;
>    while(x1<=x2)
>    {
>      x=(x1+x2)/2;
>      k=strcmp(st,word[x]);
>      if(k==0) return x;
>      if(k>0) x1=x+1;
>      else x2=x-1;  
>    }
>    return 0;      
> } */   
> int find2(char *st)
> {
>     int i;
>     for(i=1;i<=N;i++)
>     {
>       if(strcmp(st,word[i])==0) return i;  
>     }  
>     return 0;  
> }     
> int letterMissing(char *st,char *ch,int k,int L)
> {
>     int i,j,flag;
>     flag=0;
>    if(k==1)//L>len
>    {  flag=0;
>      for(i=0,j=0;i<L;i++)
>      {
>        if(st[i]!=ch[j]&&flag==0) { flag=1;  continue; }  
>        if(st[i]!=ch[j]) return 0;
>        j++;
>      }
>      return 1;       
>    }
>    else if(k==-1)
>    {  flag=0;
>      for(i=0,j=0;i<L;j++)
>      {
>        if(st[i]!=ch[j]&&flag==0) { flag=1; continue; }   
>        if(st[i]!=ch[j]) return 0;
>        i++;
>      }
>      return 1;      
>    }        
>    return 1; 
> }    
> int letterWrong(char *st,char *ch,int L)
> {
>     int i,j,flag;
>     flag=0;
>     for(i=0;i<L;i++)
>     {
>       if(st[i]!=ch[i]&&flag==0) { flag=1; continue; }  
>       if(st[i]!=ch[i]) return 0;
>     } 
>     return 1;   
> }    
> int orderWrong(char *st,char *ch,int L)
> {
>     int i,j,flag;
>     flag=0; L--;
>     for(i=0;i<L;i++)
>     {
>         if(st[i]!=ch[i]&&flag==0)
>         {            
>             if(st[i+1]==ch[i]&&st[i]==ch[i+1])
>             { 
>                 i++;
>             }
>             else return 0;   
>              
>              flag=1; continue; 
>         }
>         if(st[i]!=ch[i]) return 0;        
>     }    
>     return 1;
> }    
> void process(char *st)
> {
>   int L,i,j,k,flag;
>   L=strlen(st); 
>   flag=0;
>   for(i=1;i<=N;i++)
>   {
>      k=L-len[i];
>     if(k==1||k==-1) 
>     {
>       //  printf("kkk==%d\n",k);
>       if(letterMissing(st,word[i],k,L)) { flag=1; break; }  
>     }
>     else if(k==0) 
>     {
>       if(letterWrong(st,word[i],L)) {flag=1; break;}
>       if(orderWrong(st,word[i],L)) {flag=1; break;}
>     }            
>   }
>   if(flag) printf("%s is a misspelling of %s\n",st,word[i]);      
>   else printf("%s is unknown\n",st);
> }    
> int main()
> {
>     int i,j,k,q;
>     char st[30];
>     scanf("%d",&N);
>     for(i=1;i<=N;i++) scanf("%s",word[i]);
> //    qsort(word+1,N,sizeof(word[1]),sort);
>     for(i=1;i<=N;i++) len[i]=strlen(word[i]);
>     scanf("%d",&q);
>     while(q--)
>     {
>       scanf("%s",st);
>       if(find2(st)) { printf("%s is correct\n",st); continue; }
>       process(st);      
>     }    
>     return 0;    
> }    
> /*Sample Input
> 
> 
> 11
> this
> is
> a
> dictionary
> that
> we
> will
> use
> for
> us
> letter
> 60
> su
> as
> the
> dictonary
> us
> willl
> 
> Sample Output
> 
> 
> 
> su is a misspelling of us
> as is a misspelling of is
> the is unknown
> dictonary is a misspelling of dictionary
> us is correct
> willl is a misspelling of will
> */

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