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 SLdragon at 2012-04-03 22:32:48 on Problem 2192

代码的大概意思是:
输入的字符串 x,y,z
先在z中先搜索x,并标记下这些字母在z中的位置,记录在temp里,然后在z中除去x后搜索y,如果满足,就返回成功。compare(x,y,z)
然后在z中先搜索y,并标记下这些字母在z中的位置,记录在temp里,然后在z中除去y后搜索x,如果满足,就返回成功。compare(y,x,z)

两次搜索中有一次成功,则说明满足题意。(compare(x,y,z)||compare(y,x,z));


#include<stdio.h>
#include<string.h>

int compare(char x[],char y[],char z[])
{
        int xx,yy,len_x,len_y,len_z,j,k;
        int temp[600];
        xx=0;
        yy=0;
        len_x=strlen(x);
        len_y=strlen(y);
        len_z=strlen(z);


        for(k=0;k<len_z;k++)
            temp[k]=0;
                               
        for(j=0;j<len_z;j++)
        {
            if(xx<len_x&&z[j]==x[xx])
            {
                xx++;
                temp[j]=1;
            }
        }                
        if(xx==len_x)//表示搜索到了x
        {
            for(j=0;j<len_z;j++)
            {
                if(yy<len_y&&z[j]==y[yy]&&temp[j]==0)
                        yy++;          
            }
            if(yy==len_y)//同时找到了x,y
                return 1;    
        }
//没搜索到x或y,则搜索不成功
        return 0;
}

int main()
{
    int n,i;
    char x[300],y[300],z[600];
    scanf("%d",&n);    
    for(i=0;i<n;i++)
    {
        scanf("%s %s %s",x,y,z);
        if(compare(x,y,z)||compare(y,x,z))
           printf("Data set %d: yes\n",i+1);
        else
            printf("Data set %d: no\n",i+1);
    }
    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