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

请高手指点:为什么总是WA?

Posted by lxt at 2006-07-20 16:07:49 on Problem 1035
SAMPLE似乎每问题,但一运行......

#include<stdio.h>
#include<string.h>
#include<math.h>
int check(char a[],char b[],int l1,int l2)
{int i,j,s=0,p,left1=0,left2=0,right1=l1-1,right2=l2-1;
 
 if(l1==l2)
 {for(i=0;i<=right1;i++)
   if(a[i]!=b[i]){s=1;break;}
   if(s==0)return 1;        
  for(j=right1;j>i;j--)
   if(a[j]!=b[j])return 0; 
   return 2;}
 
  if(l1>l2)p=l1;
  else p=l2;
  while((left1<l1)&&(left2<l2))
    if(a[left1++]==b[left2++])p--;       
    else break;
    while((right1>=0)&&(right2>=0))
    if(a[right1--]==b[right2--])p--;
    else break;
  if(p==1)return 2;
  return 0;}



int main()
{int i,j,q,l1[10020],l2[550],right,top1=-1,top2=-1,top,t[1000];
char dit[10020][20],run[550][20];

while(1)
{scanf("%s",dit[++top1]);
 l1[top1]=strlen(dit[top1]);
 if((l1[top1]==1)&&(dit[top1][0]=='#'))
 {top1--;break;}}
while(1)
{scanf("%s",run[++top2]);
 l2[top2]=strlen(run[top2]);
 if((l2[top2]==1)&&(run[top2][0]=='#'))
 {top2--;break;}}

for(i=0;i<=top2;i++)
{top=0;right=0;
 for(j=0;j<=top1;j++)
 if(fabs(l1[j]-l2[i])<2)
  {q=check(dit[j],run[i],l1[j],l2[i]);
  if(q==1){right=1;break;}
  if(q==2)t[++top]=j;}
 if(right==1)printf("%s is correct\n",run[i]); 
 else{printf("%s:",run[i]);
  for(j=1;j<=top;j++)
  printf(" %s",dit[t[j]]);
  printf("\n");
}}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