#1177: 我不懂...第8個測資


B88000005 (喔~~!!XD)

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

#include <iostream>
#include <string>
using namespace std;

int main()
{
    char x[4000],y[4000];
    int X=0,Y=0;
    while(cin>>x){
        X=0;
        Y=0;
        if(x[0]=='#'){
            break;
        }
        cin>>y;
        for(int i=0;i<strlen(x);i++){
            if(x[i]=='I'){
                X+=1;
            }
            if(x[i]=='V'){
                X+=5;
                if((i!=0)&&(x[i-1]=='I')){
                    X-=2;
                }
            }
            if(x[i]=='X'){
                X+=10;
                if((i!=0)&&(x[i-1]=='I')){
                    X-=2;
                }
                if((i!=0)&&(x[i-1]=='V')){
                    X-=10;
                }
            }
            if(x[i]=='L'){
                X+=50;
                if((i!=0)&&(x[i-1]=='I')){
                    X-=2;
                }
                if((i!=0)&&(x[i-1]=='V')){
                    X-=10;
                }
                if((i!=0)&&(x[i-1]=='X')){
                    X-=20;
                }
            }
            if(x[i]=='C'){
                X+=100;
                if((i!=0)&&(x[i-1]=='I')){
                    X-=2;
                }
                if((i!=0)&&(x[i-1]=='V')){
                    X-=10;
                }
                if((i!=0)&&(x[i-1]=='X')){
                    X-=20;
                }
                if((i!=0)&&(x[i-1]=='L')){
                    X-=100;
                }
            }
            if(x[i]=='D'){
                X+=500;
                if((i!=0)&&(x[i-1]=='I')){
                    X-=2;
                }
                if((i!=0)&&(x[i-1]=='V')){
                    X-=10;
                }
                if((i!=0)&&(x[i-1]=='X')){
                    X-=20;
                }
                if((i!=0)&&(x[i-1]=='L')){
                    X-=100;
                }
                if((i!=0)&&(x[i-1]=='C')){
                    X-=200;
                }
            }
            if(x[i]=='M'){
                X+=1000;
                if((i!=0)&&(x[i-1]=='I')){
                    X-=2;
                }
                if((i!=0)&&(x[i-1]=='V')){
                    X-=10;
                }
                if((i!=0)&&(x[i-1]=='X')){
                    X-=20;
                }
                if((i!=0)&&(x[i-1]=='L')){
                    X-=100;
                }
                if((i!=0)&&(x[i-1]=='C')){
                    X-=200;
                }
                if((i!=0)&&(x[i-1]=='D')){
                    X-=1000;
                }
            }
        }
        for(int i=0;i<strlen(y);i++){
            if(y[i]=='I'){
                Y+=1;
            }
            if(y[i]=='V'){
                Y+=5;
                if((i!=0)&&(y[i-1]=='I')){
                    Y-=2;
                }
            }
            if(y[i]=='X'){
                Y+=10;
                if((i!=0)&&(y[i-1]=='I')){
                    Y-=2;
                }
                if((i!=0)&&(y[i-1]=='V')){
                    Y-=10;
                }
            }
            if(y[i]=='L'){
                Y+=50;
                if((i!=0)&&(y[i-1]=='I')){
                    Y-=2;
                }
                if((i!=0)&&(y[i-1]=='V')){
                    Y-=10;
                }
                if((i!=0)&&(y[i-1]=='X')){
                    Y-=20;
                }
            }
            if(y[i]=='C'){
                Y+=100;
                if((i!=0)&&(y[i-1]=='I')){
                    Y-=2;
                }
                if((i!=0)&&(y[i-1]=='V')){
                    Y-=10;
                }
                if((i!=0)&&(y[i-1]=='X')){
                    Y-=20;
                }
                if((i!=0)&&(y[i-1]=='L')){
                    Y-=100;
                }
            }
            if(y[i]=='D'){
                Y+=500;
                if((i!=0)&&(y[i-1]=='I')){
                    Y-=2;
                }
                if((i!=0)&&(y[i-1]=='V')){
                    Y-=10;
                }
                if((i!=0)&&(y[i-1]=='X')){
                    Y-=20;
                }
                if((i!=0)&&(y[i-1]=='L')){
                    Y-=100;
                }
                if((i!=0)&&(y[i-1]=='C')){
                    Y-=200;
                }
            }
            if(y[i]=='M'){
                Y+=1000;
                if((i!=0)&&(y[i-1]=='I')){
                    Y-=2;
                }
                if((i!=0)&&(y[i-1]=='V')){
                    Y-=10;
                }
                if((i!=0)&&(y[i-1]=='X')){
                    Y-=20;
                }
                if((i!=0)&&(y[i-1]=='L')){
                    Y-=100;
                }
                if((i!=0)&&(y[i-1]=='C')){
                    Y-=200;
                }
                if((i!=0)&&(y[i-1]=='D')){
                    Y-=1000;
                }
            }
        }
        X-=Y;
        if(X==0){
            cout<<"ZERO"<<endl;
            continue;
        }
        string k;
        while(X>=1000){
            X-=1000;
            k+='M';
        }
        while(X>=500){
            X-=500;
            k+='D';
        }
        while(X>=100){
            X-=100;
            k+='C';
        }
        while(X>=50){
            X-=50;
            k+='L';
        }
        while(X>=10){
            X-=10;
            k+='X';
        }
        while(X>=5){
            X-=5;
            k+='V';
        }
        while(X>=1){
            X-=1;
            k+='I';
        }
        int c12=k.find("DCCCC", 0);
        if(c12>=0){
            k.erase(c12,3);
            k[c12]='C';
            k[c12+1]='M';
        }
        int c1=k.find("CCCC", 0);
        if(c1>=0){
            k.erase(c1,2);
            k[c1]='C';
            k[c1+1]='D';
        }
        int c22=k.find("LXXXX", 0);
        if(c22>=0){
            k.erase(c22,3);
            k[c22]='X';
            k[c22+1]='C';
        }
        int c2=k.find("XXXX", 0);
        if(c2>=0){
            k.erase(c2,2);
            k[c2]='X';
            k[c2+1]='L';
        }
        int c32=k.find("VIIII", 0);
        if(c32>=0){
            k.erase(c32,3);
            k[c32]='I';
            k[c32+1]='X';
        }
        int c3=k.find("IIII", 0);
        if(c3>=0){
            k.erase(c3,2);
            k[c3]='I';
            k[c3+1]='V';
        }
        cout<<k<<endl;
    }
    return 0;
}

 

這樣應該是不可能錯了吧??

 

結果:

 

與正確輸出不相符(line:8)
您的答案為: XXX
正確答案為: XVIII
 

 
#1182: Re:我不懂...第8個測資


kaji (加持)

學校 : 銘傳大學
編號 : 2802
來源 : [61.219.36.23]
最後登入時間 :
2009-10-22 23:39:20
a013. 羅馬數字 -- NPSC 模擬試題 | From: [218.160.34.212] | 發表日期 : 2009-01-17 21:21

我直接複製貼上題目部分內容:

在這一題工作是讀入兩個正整數,然後輸出兩個數字差的絕對值。

 

因為程式碼太長所以我只跳著看了一下,

好像是沒有看到你做數字差的絕對值。

 

然後補充一下我的猜測:

你輸出的 XXX 是第九或更之後的測資

 
#1185: Re:我不懂...第8個測資


B88000005 (喔~~!!XD)

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

我直接複製貼上題目部分內容:

在這一題工作是讀入兩個正整數,然後輸出兩個數字差的絕對值。

 

因為程式碼太長所以我只跳著看了一下,

好像是沒有看到你做數字差的絕對值。

 

然後補充一下我的猜測:

你輸出的 XXX 是第九或更之後的測資


哈哈!!原來如此= =""

謝謝你的回覆^^!

 
ZeroJudge Forum