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

请教,这种做法为什么不行呢?

Posted by 2012xie at 2013-02-12 10:34:09 on Problem 2192
#include<stdio.h>///2192
#include<string.h>
#define num 202
char s1[num],s2[num],s3[num];
int i1,i2,i3;
int len1,len2,len3;
void fun()
{
    int j;
    i1=i2=i3=0;
    while(i3<len3)
    {
        if(s1[i1]!=s3[i3]&&s2[i2]!=s3[i3])
        {
            printf("no\n");
            return ;
        }
        if(s1[i1]==s3[i3]&&s2[i2]==s3[i3])
        {
            j=0;
            while(s1[i1+j]==s3[i3+j]&&s2[i2+j]==s3[i3+j])
            {
                j++;
            }
            if(s1[i1+j]==s3[i3+j])
            {
                i1+=j;
                i3+=j;
            }
            else if(s2[i2+j]==s3[i3+j])
            {
                i2+=j;
                i3+=j;
            }
            else
            {
                printf("no\n");
                return ;
            }
        }
        else if(s1[i1]==s3[i3])
        {
            i1++;
            i3++;
        }
        else if(s2[i2]==s3[i3])
        {
            i2++;
            i3++;
        }
    }
    printf("yes\n");
}
int main()
{
    //freopen("input.txt","r",stdin);
    int n,count,i,j;
    scanf("%d",&n);
    for(count=1;count<=n;count++)
    {
        printf("Data set %d: ",count);
        scanf("%s%s%s",s1,s2,s3);
        len1=strlen(s1);
        len2=strlen(s2);
        len3=strlen(s3);
        if(len1+len2!=len3)
        {
            printf("no\n");
            continue;
        }
        fun();
    }
}

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