#14282: 請問這樣為甚麼錯


s940063t (lihchyi)

學校 : 元智大學
編號 : 77006
來源 : [220.135.42.39]
最後登入時間 :
2018-12-18 00:46:20
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [115.82.199.65] | 發表日期 : 2018-07-10 14:05

#include <iostream>
#include<math.h>
using namespace std;
int main()
{ //579 1110 717
int n,m;//123 456 555 555 123 594
while (true)
{

cin >> n >> m;
if (n == 0 && m == 0)
{
break;
}
int carry = 0;
int n_1,m_1;
while (n != 0 && m != 0)
{
n_1 = n % 10;
m_1 = m % 10;
n /= 10;
m /= 10;
if ((n_1 + m_1) >= 10)
{
carry += 1;
n += 1;
}
}
if (carry == 0)
{
cout << "No carry operation." << endl;
}
else if (carry == 1)
{
cout << carry << " carry operation." << endl;
}
else
{
cout << carry << " carry operations." << endl;
}
}
return 0;
}

 
#14287: Re:請問這樣為甚麼錯


kev8067@gmail.com (卓承緯)

學校 : 不指定學校
編號 : 74409
來源 : []
最後登入時間 :
2018-01-11 15:15:59
c014. 10035 - Primary Arithmetic -- UVa10035 | From: [114.136.224.188] | 發表日期 : 2018-07-10 14:56

#include
#include
using namespace std;
int main()
{ //579 1110 717
int n,m;//123 456 555 555 123 594
while (true)
{

cin >> n >> m;
if (n == 0 && m == 0)
{
break;
}
int carry = 0;
int n_1,m_1;
while (n != 0 && m != 0)
{
n_1 = n % 10;
m_1 = m % 10;
n /= 10;
m /= 10;
if ((n_1 + m_1) >= 10)
{
carry += 1;
n += 1;
}
}
if (carry == 0)
{
cout << "No carry operation." << endl;
}
else if (carry == 1)
{
cout << carry << " carry operation." << endl;
}
else
{
cout << carry << " carry operations." << endl;
}
}
return 0;
}


955 45 答案是錯的 可以再思考查一下 

 
ZeroJudge Forum