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 suibian at 2005-09-15 15:39:46 on Problem 2615
#include <stdio.h>

int qy(char* a, int i, int j)
{
    while(i<=j && a[i]==a[j]) {i++; j--;}
    if(i>j) return 1;
    else return 0;
}

int main()
{
    char s1[1001], s2[1001];
    int l1, l2, l;
    int ok;
    int i, j;
    int found;
    int r1, r2;

    while(gets(s1)) {
        found=0;
        gets(s2);
        if(strcmp(s1, s2)==0) {printf("No Solution.\n"); continue;}
        l1=strlen(s1);
        l2=strlen(s2);
        l=(l1<=l2)?l1:l2;
        ok=1;
        for(i=-1;i<=l-1;i++) {
            if(s1[i]!=s2[i]) ok=0;
            r1=qy(s1, i+1, l1-1);
            r2=qy(s2, i+1, l2-1);
            if(r1==1 && r2==0) {
                for(j=i;j>=0;j--) printf("%c", s1[j]);
                found=1;
                break;
            }
            else if(r2==1 && r1==0) {
                for(j=i;j>=0;j--) printf("%c", s2[j]);
                found=1;
                break;
            }
            if(!ok) {
                if(r1==1 && r2==1) {
                    j=i;
                    while(s1[j]==s2[j]) j--;
                    if(s1[j]<s2[j]) {
                        for(j=i;j>=0;j--) printf("%c", s1[j]);
                        found=1;
                        break;
                    }
                    else {
                        for(j=i;j>=0;j--) printf("%c", s2[j]);
                        found=1;
                        break;
                    }
                }
            }
        }
        if(found) {printf("\n"); continue;}
        if(l1<l2) {
            if(s2[l1]=='a') printf("b");
            else printf("a");
            for(i=l1-1;i>=0;i--) printf("%c", s1[i]);
        }
        if(l2<l1) {
            if(s1[l2]=='a') printf("b");
            else printf("a");
            for(i=l2-1;i>=0;i--) printf("%c", s2[i]);
        }
        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