#26727: WA (line:1222)


jinyulin34@gmail.com (jinyulink)

學校 : 國立中央大學
編號 : 82369
來源 : [140.115.213.3]
最後登入時間 :
2023-02-21 10:59:45
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [101.137.124.196] | 發表日期 : 2021-08-21 23:25

有人可以幫忙看一下嗎? 

WA (line:1222)

不知道哪裡出錯了

//https://zerojudge.tw/ShowProblem?problemid=c014
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a,b;
    a=1;
    b=1;
    while(a!=0&&b!=0)
    {
        cin>>a>>b;
        if(a==0&&b==0)
        {
            break;
        }
        else
        {
            int aa[11],bb[11]; //將每一位的數字存進陣列
            memset(aa,0,sizeof(aa));
            memset(bb,0,sizeof(bb));
            int an,bn; //a,b的位數
            for(int i=1;i<=9;i++)
            {
                if(a<pow(10,i))
                {
                    an=i;
                    break;
                }
            }
            for(int i=1;i<=9;i++)
            {
                if(b<pow(10,i))
                {
                    bn=i;
                    break;
                }
            }
            int aaa=a;
            for(int i=an-1;i>=0;i--)
            {
                int z=aaa/pow(10,i);
                aa[i]=z;
                aaa-=z*pow(10,i);
            }
            int bbb=b;
            for(int i=bn-1;i>=0;i--)
            {
                int z=bbb/pow(10,i);
                bb[i]=z;
                bbb-=z*pow(10,i);
            }
            int f=bn+1;
            if(an>=bn)
            {
                f=an+1;
            }
            int o=0;
            for(int i=0;i<f;i++)
            {
                if(aa[i]+bb[i]>=10)
                {
                    aa[i+1]++;
                    o++;
                }
            }
            if(o==0)
            {
                cout<<"No carry operation."<<endl;
            }
            else if(o==1)
            {
                cout<<o<<" carry operation."<<endl;
            }
            else
            {
                cout<<o<<" carry operations."<<endl;
            }
        }
    }
    return 0;
}
 
#26731: Re:WA (line:1222)


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.9.74.255]
最後登入時間 :
2024-10-14 22:20:08
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [39.11.200.251] | 發表日期 : 2021-08-22 09:29

有人可以幫忙看一下嗎? 

WA (line:1222)

不知道哪裡出錯了

//https://zerojudge.tw/ShowProblem?problemid=c014
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a,b;
    a=1;
    b=1;
    while(a!=0&&b!=0)
    {
        cin>>a>>b;
        if(a==0&&b==0)
        {
            break;
        }
        else
        {
            int aa[11],bb[11]; //將每一位的數字存進陣列
            memset(aa,0,sizeof(aa));
            memset(bb,0,sizeof(bb));
            int an,bn; //a,b的位數
            for(int i=1;i<=9;i++)
            {
                if(a<pow(10,i))
                {
                    an=i;
                    break;
                }
            }
            for(int i=1;i<=9;i++)
            {
                if(b<pow(10,i))
                {
                    bn=i;
                    break;
                }
            }
            int aaa=a;
            for(int i=an-1;i>=0;i--)
            {
                int z=aaa/pow(10,i);
                aa[i]=z;
                aaa-=z*pow(10,i);
            }
            int bbb=b;
            for(int i=bn-1;i>=0;i--)
            {
                int z=bbb/pow(10,i);
                bb[i]=z;
                bbb-=z*pow(10,i);
            }
            int f=bn+1;
            if(an>=bn)
            {
                f=an+1;
            }
            int o=0;
            for(int i=0;i<f;i++)
            {
                if(aa[i]+bb[i]>=10)
                {
                    aa[i+1]++;
                    o++;
                }
            }
            if(o==0)
            {
                cout<<"No carry operation."<<endl;
            }
            else if(o==1)
            {
                cout<<o<<" carry operation."<<endl;
            }
            else
            {
                cout<<o<<" carry operations."<<endl;
            }
        }
    }
    return 0;
}

把while(a!=0&&b!=0)改成while(true)就可以了

我覺得這題的題目寫錯了,輸入說明說「2個正整數」,但實際上有可能其中一個是0

 
#26732: Re:WA (line:1222)


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.9.74.255]
最後登入時間 :
2024-10-14 22:20:08
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [39.11.200.251] | 發表日期 : 2021-08-22 09:33

有人可以幫忙看一下嗎? 

WA (line:1222)

不知道哪裡出錯了

//https://zerojudge.tw/ShowProblem?problemid=c014
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a,b;
    a=1;
    b=1;
    while(a!=0&&b!=0)
    {
        cin>>a>>b;
        if(a==0&&b==0)
        {
            break;
        }
        else
        {
            int aa[11],bb[11]; //將每一位的數字存進陣列
            memset(aa,0,sizeof(aa));
            memset(bb,0,sizeof(bb));
            int an,bn; //a,b的位數
            for(int i=1;i<=9;i++)
            {
                if(a<pow(10,i))
                {
                    an=i;
                    break;
                }
            }
            for(int i=1;i<=9;i++)
            {
                if(b<pow(10,i))
                {
                    bn=i;
                    break;
                }
            }
            int aaa=a;
            for(int i=an-1;i>=0;i--)
            {
                int z=aaa/pow(10,i);
                aa[i]=z;
                aaa-=z*pow(10,i);
            }
            int bbb=b;
            for(int i=bn-1;i>=0;i--)
            {
                int z=bbb/pow(10,i);
                bb[i]=z;
                bbb-=z*pow(10,i);
            }
            int f=bn+1;
            if(an>=bn)
            {
                f=an+1;
            }
            int o=0;
            for(int i=0;i<f;i++)
            {
                if(aa[i]+bb[i]>=10)
                {
                    aa[i+1]++;
                    o++;
                }
            }
            if(o==0)
            {
                cout<<"No carry operation."<<endl;
            }
            else if(o==1)
            {
                cout<<o<<" carry operation."<<endl;
            }
            else
            {
                cout<<o<<" carry operations."<<endl;
            }
        }
    }
    return 0;
}

把while(a!=0&&b!=0)改成while(true)就可以了

我覺得這題的題目寫錯了,輸入說明說「2個正整數」,但實際上有可能其中一個是0

找到了原文:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=976

原文裡面說的是"two unsigned integers",0也包括在內

 
#26755: Re:WA (line:1222)


jinyulin34@gmail.com (jinyulink)

學校 : 國立中央大學
編號 : 82369
來源 : [140.115.213.3]
最後登入時間 :
2023-02-21 10:59:45
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [101.137.6.185] | 發表日期 : 2021-08-23 10:30

有人可以幫忙看一下嗎? 

WA (line:1222)

不知道哪裡出錯了

//https://zerojudge.tw/ShowProblem?problemid=c014
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a,b;
    a=1;
    b=1;
    while(a!=0&&b!=0)
    {
        cin>>a>>b;
        if(a==0&&b==0)
        {
            break;
        }
        else
        {
            int aa[11],bb[11]; //將每一位的數字存進陣列
            memset(aa,0,sizeof(aa));
            memset(bb,0,sizeof(bb));
            int an,bn; //a,b的位數
            for(int i=1;i<=9;i++)
            {
                if(a<pow(10,i))
                {
                    an=i;
                    break;
                }
            }
            for(int i=1;i<=9;i++)
            {
                if(b<pow(10,i))
                {
                    bn=i;
                    break;
                }
            }
            int aaa=a;
            for(int i=an-1;i>=0;i--)
            {
                int z=aaa/pow(10,i);
                aa[i]=z;
                aaa-=z*pow(10,i);
            }
            int bbb=b;
            for(int i=bn-1;i>=0;i--)
            {
                int z=bbb/pow(10,i);
                bb[i]=z;
                bbb-=z*pow(10,i);
            }
            int f=bn+1;
            if(an>=bn)
            {
                f=an+1;
            }
            int o=0;
            for(int i=0;i<f;i++)
            {
                if(aa[i]+bb[i]>=10)
                {
                    aa[i+1]++;
                    o++;
                }
            }
            if(o==0)
            {
                cout<<"No carry operation."<<endl;
            }
            else if(o==1)
            {
                cout<<o<<" carry operation."<<endl;
            }
            else
            {
                cout<<o<<" carry operations."<<endl;
            }
        }
    }
    return 0;
}

把while(a!=0&&b!=0)改成while(true)就可以了

我覺得這題的題目寫錯了,輸入說明說「2個正整數」,但實際上有可能其中一個是0

找到了原文:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=976

原文裡面說的是"two unsigned integers",0也包括在內

 

原來是這樣!! 我總算ac了 謝謝你的回覆

 
ZeroJudge Forum