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

POJ能过,但是Uva却WA,各位大神帮我看看啊~~~~

Posted by xiexinxinlove at 2014-07-10 21:22:45 on Problem 1102
这个题POJ能过,但在Uva 706 提交的时候却WA了,这是我的代码:
#include <stdio.h>
#include <string.h>
int main()
{
    int s,n;
    int i,j,k;
    int len;
    char a[15];
    while(scanf("%d",&s))
    {
        getchar();
        gets(a);
        len=strlen(a);
        if(s == 0 && a[0] == '0' && len == 1)
          break;
        //1、输出第1行 
        for(j=0; j<len; j++)
        {
            if(a[j] == '0' || a[j] == '2' || a[j] == '3' || a[j] == '5' || a[j] == '6' || a[j] == '7' || a[j] == '8' || a[j] == '9')
            {
                printf(" "); 
                for(k=1; k<=s; k++)
                {
                    printf("-"); 
                }
                printf(" ");
            }
            else if(a[j] == '1' || a[j] == '4')
            {
                for(k=1; k<=s+2; k++)
                {
                    printf(" "); 
                }
            } 
            if(a[j+1] != '\0')
              printf(" "); //隔开列
        }
        printf("\n"); 
           
        //2、输出第2~s+1行 (1~s)
        for(i=1; i<=s; i++)
        {
            for(j=0; j<len; j++)
            {
                if(a[j] == '1' || a[j] == '2' || a[j] == '3' || a[j] == '7')
                {
                    for(k=1; k<=s+1; k++)
                    {
                        printf(" ");
                    }
                    printf("|");
                }
                else if(a[j] == '5' || a[j] == '6')
                {
                    printf("|");
                    for(k=1; k<=s+1; k++)
                    {
                        printf(" ");
                    }
                }
                else if(a[j] == '4' || a[j] == '8' || a[j] == '9' || a[j] == '0')
                {
                    printf("|");
                    for(k=1; k<=s; k++)
                    {
                        printf(" ");
                    }
                    printf("|");
                }
                if(a[j+1] != '\0')
                 printf(" "); //隔开列
            }
            printf("\n"); 
        }
        
        //3、输出第s+2行
        for(j=0; j<len; j++)
        {
            if(a[j] == '2' || a[j] == '3' || a[j] == '4' || a[j] == '5' || a[j] == '6' || a[j] == '8' || a[j] == '9')
            {

                printf(" ");
                for(k=1; k<=s; k++)
                {
                    printf("-");
                }
                printf(" ");
            }
            else if(a[j] == '0' || a[j] == '1' || a[j] == '7')
            {
                for(k=1; k<=s+2; k++)
                {
                    printf(" ");
                }
            }
            if(a[j+1] != '\0')
                 printf(" "); //隔开列 
        }
        printf("\n");
        
        //4、输出第s+3行~2s+2行(1~s) 
        for(i=1; i<=s; i++)
        {
            for(j=0; j<len; j++)
            {
                if(a[j] == '1' || a[j] == '3' || a[j] == '4' || a[j] == '5' || a[j] == '7' || a[j] == '9')
                {
                    for(k=1; k<=s+1; k++)
                    {
                        printf(" ");
                    }
                    printf("|");
                }
                else if(a[j] == '0' || a[j] == '8' || a[j] == '6')
                {
                    printf("|");
                    for(k=1; k<=s; k++)
                    {
                        printf(" ");
                    }
                    printf("|");
                }
                else if(a[j] == '2')  //必须写成 else if(a[j] == 2)不能写成else,因为如果输入的是异常情况,就不能输出 
                {
                    printf("|");
                    for(k=1; k<=s+1; k++)
                    {
                        printf(" ");
                    }
                }  
            if(a[j+1] != '\0')
                 printf(" "); //隔开列
            }
             printf("\n"); 
        }
        
        //5、输出2s+3行
        for(j=0; j<len; j++)
        {
            if(a[j] == '0' || a[j] == '2' || a[j] == '3' || a[j] == '5' || a[j] == '6' || a[j] == '8' || a[j] == '9')
            {
                printf(" ");
                for(k=1; k<=s; k++)
                {
                    printf("-");
                }
                printf(" ");
            }
            else if(a[j] == '1' || a[j] == '4' || a[j] == '7')
            {
                for(k=1; k<=s+2; k++)
                {
                    printf(" ");
                }
            }
            if(a[j+1] != '\0')
                 printf(" "); //隔开列
        }
         printf("\n\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