#256: 羅馬那題


dream1x (jizz)

學校 : 黎明技術學院
編號 : 1573
來源 : [111.240.64.180]
最後登入時間 :
2012-07-10 21:59:55
a013. 羅馬數字 -- NPSC 模擬試題 | From: [210.71.22.14] | 發表日期 : 2008-04-16 19:17

關於這一題 我解出來了 但是不知道為什麼 他都給我WA 我在我電腦測試都對

 #include<stdio.h>
#include<stdlib.h>

int munber( char x )
{
    if( x == 'I' ) return 1;
    if( x == 'V' ) return 5;
    if( x == 'X' ) return 10;
    if( x == 'L' ) return 50;
    if( x == 'C' ) return 100;
    if( x == 'D' ) return 500;
    if( x == 'M' ) return 1000;
}

void ret( int x , int y )
{
    int tmp = x - y;
    if( tmp == 0 )
    {
        printf("ZERO\n");
    }
    else
    {
        while( tmp >= 1000 )
        {
               printf("M");
               tmp -= 1000;
        }
        if( tmp >= 900 )
        {
            tmp -= 900;
            printf("CM");
        }
        if( tmp >= 500 )
        {
            tmp -= 500;
            printf("D");
        }
        if( tmp >= 400 )
        {
               printf("CD");
               tmp -= 400;
        }
        while( tmp >= 100 )
        {
               printf("C");
               tmp -= 100;
        }
        if( tmp >= 90 )
        {
            printf("XC");
            tmp -= 90;
        }
        if( tmp >= 50 )
        {
            printf("L");
            tmp -= 50;
        }
        if( tmp >= 40 )
        {
            printf("XL");
            tmp -= 40;
        }
        while( tmp >= 10 )
        {
             printf("X");
             tmp -= 10;
        }
        if( tmp >= 9 )
        {
            printf("IX");
            tmp -= 9;
        }
        if( tmp >= 5 )
        {
            printf("V");
            tmp -= 5;
        }
        if( tmp >= 4 )
        {
            printf("IV");
            tmp -= 4;
        }
        while( tmp >= 1 )
        {
             printf("I");
             tmp -= 1;
        }
        printf(" \n");
    }
}

main()
{
     int x_[30],y_[30];
     char x[30],y[30];
     int i,l,sum_1,sum_2,n=0;
      while( 1 )
      {
           scanf("%s",x);
           if( x[0]== '#' && x[1]== '\0' ) break;
           scanf("%s",y);
           sum_1 = sum_2 = 0;
           for( i = 0 ; i < strlen( x ) ; i++ )
           {
                x_[i] = munber( x[i] );
           }
           l = strlen(x);
           if( x[1] == '\0' )
           {
               sum_1 = munber( x_[0] );
           }
           else
           {
               for( i = 0 ; i < l-1 ; i++ )
               {
                    if( x_[i] < x_[i+1])
                    {
                        x_[i] -= x_[i+1];
                        x_[i+1] = 0;
                        i++;
                    }
               }
               for( i = 0 ; i < l ; i++ )
               {
                    if( x_[i] < 0 )
                        x_[i] *= -1;
                    sum_1 += x_[i];
               }
           }  
           for( i = 0 ; i < strlen( y ) ; i++ )
           {
                y_[i] = munber( y[i] );
           }
           l = strlen(y);
           if( y[1] == '\0' )
           {
              sum_2 = munber( y_[0] );   
           }   
           else
           {
               for( i = 0 ; i < l-1 ; i++ )
               {
                    if( y_[i] < y_[i+1])
                    {
                        y_[i] -= y_[i+1];
                        y_[i+1] = 0;
                        i++;
                    }
               }
               for( i = 0 ; i < l ; i++ )
               {
                    if( y_[i] < 0 )
                        y_[i] *= -1;
                    sum_2 += y_[i];
               }
           }

           if( sum_1 < sum_2 )
           {
               ret( sum_2 , sum_1 );
           }
           else
           {
               ret( sum_1 , sum_2 );
           }
      }
    return 0;
}

他給我了一個 WA 輸入 X V

說我輸出答案為 ZERO

但是我實際上是輸出 V

上網抓了資測 也沒錯誤.

 

 回報也都沒回應 SOS阿~是compiler不同的關係嗎??

 
#1148: Re:羅馬那題


B88000005 (喔~~!!XD)

學校 : 國立內壢高級中學
編號 : 4538
來源 : [118.167.234.168]
最後登入時間 :
2021-05-12 14:50:32
a013. 羅馬數字 -- NPSC 模擬試題 | From: [220.138.40.162] | 發表日期 : 2009-01-08 21:23

關於這一題 我解出來了 但是不知道為什麼 他都給我WA 我在我電腦測試都對 #include
#include

int munber( char x )
{
    if( x == 'I' ) return 1;
    if( x == 'V' ) return 5;
    if( x == 'X' ) return 10;
    if( x == 'L' ) return 50;
    if( x == 'C' ) return 100;
    if( x == 'D' ) return 500;
    if( x == 'M' ) return 1000;
}

void ret( int x , int y )
{
    int tmp = x - y;
    if( tmp == 0 )
    {
        printf("ZERO\n");
    }
    else
    {
        while( tmp >= 1000 )
        {
               printf("M");
               tmp -= 1000;
        }
        if( tmp >= 900 )
        {
            tmp -= 900;
            printf("CM");
        }
        if( tmp >= 500 )
        {
            tmp -= 500;
            printf("D");
        }
        if( tmp >= 400 )
        {
               printf("CD");
               tmp -= 400;
        }
        while( tmp >= 100 )
        {
               printf("C");
               tmp -= 100;
        }
        if( tmp >= 90 )
        {
            printf("XC");
            tmp -= 90;
        }
        if( tmp >= 50 )
        {
            printf("L");
            tmp -= 50;
        }
        if( tmp >= 40 )
        {
            printf("XL");
            tmp -= 40;
        }
        while( tmp >= 10 )
        {
             printf("X");
             tmp -= 10;
        }
        if( tmp >= 9 )
        {
            printf("IX");
            tmp -= 9;
        }
        if( tmp >= 5 )
        {
            printf("V");
            tmp -= 5;
        }
        if( tmp >= 4 )
        {
            printf("IV");
            tmp -= 4;
        }
        while( tmp >= 1 )
        {
             printf("I");
             tmp -= 1;
        }
        printf(" \n");
    }
}

main()
{
     int x_[30],y_[30];
     char x[30],y[30];
     int i,l,sum_1,sum_2,n=0;
      while( 1 )
      {
           scanf("%s",x);
           if( x[0]== '#' && x[1]== '\0' ) break;
           scanf("%s",y);
           sum_1 = sum_2 = 0;
           for( i = 0 ; i < strlen( x ) ; i++ )
           {
                x_[i] = munber( x[i] );
           }
           l = strlen(x);
           if( x[1] == '\0' )
           {
               sum_1 = munber( x_[0] );
           }
           else
           {
               for( i = 0 ; i < l-1 ; i++ )
               {
                    if( x_[i] < x_[i+1])
                    {
                        x_[i] -= x_[i+1];
                        x_[i+1] = 0;
                        i++;
                    }
               }
               for( i = 0 ; i < l ; i++ )
               {
                    if( x_[i] < 0 )
                        x_[i] *= -1;
                    sum_1 += x_[i];
               }
           }  
           for( i = 0 ; i < strlen( y ) ; i++ )
           {
                y_[i] = munber( y[i] );
           }
           l = strlen(y);
           if( y[1] == '\0' )
           {
              sum_2 = munber( y_[0] );   
           }   
           else
           {
               for( i = 0 ; i < l-1 ; i++ )
               {
                    if( y_[i] < y_[i+1])
                    {
                        y_[i] -= y_[i+1];
                        y_[i+1] = 0;
                        i++;
                    }
               }
               for( i = 0 ; i < l ; i++ )
               {
                    if( y_[i] < 0 )
                        y_[i] *= -1;
                    sum_2 += y_[i];
               }
           }

           if( sum_1 < sum_2 )
           {
               ret( sum_2 , sum_1 );
           }
           else
           {
               ret( sum_1 , sum_2 );
           }
      }
    return 0;
}

他給我了一個 WA 輸入 X V

說我輸出答案為 ZERO

但是我實際上是輸出 V

上網抓了資測 也沒錯誤.

 

 回報也都沒回應 SOS阿~是compiler不同的關係嗎??

有些測試資料的CIN中就已經有簡化了!!
 
ZeroJudge Forum