一道ACM题目 报错wrong answer

一道ACM题目 报错wrong answer
Children are taught to add multi-digit numbers from right-to-left one digit at a time.Many find the "carry" operation - in which a 1 is carried from one digit position to be added to the next - to be a significant challenge.Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty.
Each line of input contains two unsigned integers less than 10 digits.The last line of input contains 0 0.For each line of input except the last you should compute and print the number of carry operations that would result from adding the two numbers,in the format shown below.
Sample Input123 456
555 555
123 594
0 0
Output for Sample Input No carry operation.
3 carry operations.
1 carry operation.
作答:
#include
using namespace std;
int main()
{
string s1,s2;
int n=0,N=0;
int b=1;
while(b=1)
{
cin>>s1>>s2;
int c1=s1.length()-1;
int c2=s2.length()-1;
if(s1[0]=='0'&&s2[0]=='0'&&c1==0&&c2==0)break;
else
while(c1>-1&&c2>-1)
{
if(s1[c1]+s2[c2]+N>105)
N=1,n+=1;
else N=0;
c1--,c2--;
}
if(c1>-1&&s2[c2]+N>9)n+=1;
if(c2>-1&&s1[c1]+N>9)n+=1;
if(n==0)cout
lione2006 1年前 已收到1个回答 举报

hwwweb 幼苗

共回答了24个问题采纳率:91.7% 举报

加上头文件#include
s1[c1]+s2[c2]是字符相加,不是数字相加.所以是字符5加字符5.字符5的ascll码是53,所以是s1+s2是106

1年前 追问

6

lione2006 举报

还是不对

举报 hwwweb

999 1应该是3 carry operations.
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.024 s. - webmaster@yulucn.com