#10797: UVA 上debug測資全過 但是出來是WA


johnnyalan0114 (unknown)

學校 : 不指定學校
編號 : 55721
來源 : [140.116.109.191]
最後登入時間 :
2016-03-19 22:04:08
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [140.116.109.191] | 發表日期 : 2016-03-19 22:11

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int i,j,carry,k;
char num1[12],num2[12];
while(1)
{
char tmp[12]={};
scanf("%s %s",num1,num2);
i=atoi(num1);
j=atoi(num2);
if(!i&&!j) break;
strcpy(tmp,num1);
j=strlen(num1);
for(i=0;i<j;i++)
num1[i]=tmp[j-i-1];
strcpy(tmp,num2);
k=strlen(num2);
for(i=0;i<k;i++)
num2[i]=tmp[k-i-1];
//////
int check,Long;
if(j<=k)
{
check=k;
Long=j;
}
else
{
check=j;
Long=k;
}
carry=0;
char value[12]={};
for(i=0;i<check;i++)
{
if(num1[i]-48>=0&&num2[i]-48>=0)
{
value[i]+=(num1[i]-48)+(num2[i]-48);
}
else if(num1[i]-48<0&&num2[i]-48>=0)
{
value[i]+=(num2[i]-48);
}
else
value[i]+=(num1[i]-48);

if(value[i]>=10)
{
carry++;
value[i]-=10;
value[i+1]+=1;
}
}


if(carry==0)
puts("No carry operation.");
else if(carry>1)
printf("%d carry operations.\n",carry);
else
puts("1 carry operation.");

}
return 0;
}

 
ZeroJudge Forum