#1552: 請問哪裡有錯ㄋ?感激不盡!!


wujjjj (頹頹)

學校 : 不指定學校
編號 : 5462
來源 : [220.133.20.129]
最後登入時間 :
2009-07-06 14:24:26
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [220.133.20.129] | 發表日期 : 2009-03-14 17:55

#include <iostream>
using namespace std;

int max(int x, int y);
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if(a==0 && b==0)
            return 0;
           
        int ar[10],br[10],cr[10]={0};
        int ac=0,bc=0;
        while(a>0){
            ar[ac]=a%10;
            a/=10;
            ac++;
        }
        while(b>0){
            br[bc]=b%10;
            b/=10;
            bc++;
        }
       
        int t=0;
        for(int i=0; i<max(ac,bc); i++){//max 條件,避免位數不同,例如 999+1
            cr[0]=0;
            if(ar[i]+br[i]+cr[i]>=10){
                t++;
                cr[i+1]=1;
            }
        }
       
        switch(t){
            case 0 : cout<<"No carry operation.";break;
            case 1 : cout<<"1 carry operation.";break;
            default: cout<<t<<" carry operations.";break;
        }
        cout<<endl;
    }
    system("PAUSE");
    return 0;
}

int max(int x, int y)
{
    if(x>y)
        return x;
    else
        return y;
}

 

錯誤訊息:

與正確輸出不相符(line:87)
您的答案為: 3 carry operations.
正確答案為: 2 carry operations.

 
ZeroJudge Forum