一道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 significan

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/08 20:34:28
一道acm题目 报错是wrong answer Children are taught to add multi-digit numbers from right-to-left one digit at a time.Many find the

一道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 significan
一道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 Input
123 456
555 555
123 594
0 0
Output for Sample Input
No carry operation.
3 carry operations.
1 carry operation.
作答
#include
#include
using namespace std;
int main()
{
\x09string x,y;
\x09while(getline(cin,x,' '),getline(cin,y)&&x!="0"||y!="0")
\x09{
\x09
\x09\x09int n=x.length();
\x09\x09int m=y.length();
\x09\x09int max=(n>=m)?n:m;
\x09\x09int min=(n=m)?x:y;
\x09\x09string mins=(n0;i--)
\x09\x09{
\x09\x09\x09if(maxs[max-1]+mins[min-1]>=106||maxs[max-1]>=58)
\x09\x09\x09{
\x09\x09\x09\x09count++;
\x09\x09\x09\x09maxs[max-2]++;
\x09\x09\x09\x09max--;
\x09\x09\x09\x09min--;
\x09\x09\x09
\x09\x09\x09}
\x09\x09\x09else
\x09\x09\x09{
\x09\x09
\x09\x09\x09\x09max--;
\x09\x09\x09\x09min--;
\x09\x09\x09}
\x09\x09
\x09\x09}
\x09 if(count>1)
\x09 {
\x09 \x09cout

一道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 significan
最明显的错误,就是
No carry operation.


这些最后面都有一个句号.你的输出没有.


这题是算有多少次进位吧,你是模拟加法运算,
if(maxs[max-1]+mins[min-1]>=106||maxs[max-1]>=58) 这些别人只能猜出来是什么意思,


maxs[max-2]++;这个百分百溢出 .当max = 1的时候  ,即原来的长度是1
没必要用字符串.
#include <iostream>
using namespace std;

int main()
{
\x09unsigned ua, ub;
\x09while(cin >> ua >> ub)
\x09{
\x09\x09if( ua == 0 && ub == 0) break;
\x09\x09// 只要依次抽出最后一位,看下有没有进位就可以.
\x09\x09int ntimes = 0;
\x09\x09int nCarry = 0;
\x09\x09// 循环的条件 ua,ub有一个不为0 
\x09\x09while( ua != 0 || ub != 0)
\x09\x09{
\x09\x09\x09unsigned a = ua % 10;
\x09\x09\x09unsigned b = ub % 10;
\x09\x09\x09if( a + b + nCarry >= 10)
\x09\x09\x09{
\x09\x09\x09\x09nCarry = 1;
\x09\x09\x09\x09ntimes ++ ;
\x09\x09\x09}
\x09\x09\x09else
\x09\x09\x09\x09nCarry = 0;
\x09\x09\x09if(ua == 0 && nCarry == 0) break;
\x09\x09\x09if(ub == 0 && nCarry == 0) break;\x09// 如果其中有一个为0,且没有进位,则退出
\x09\x09\x09ua /= 10;
\x09\x09\x09ub /= 10;
\x09\x09}
\x09\x09if( nCarry == 1)
\x09\x09\x09ntimes ++;
\x09\x09if(ntimes == 0)
\x09\x09\x09cout << "No carry operation." << endl;
\x09\x09else if(ntimes == 1)
\x09\x09\x09cout << "1 carry operation." << endl;
\x09\x09else
\x09\x09\x09cout << ntimes << " carry operation." << endl;

\x09}
\x09return  0;
}

一道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 significan 一道ACM题目 报错wrong answerChildren 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 ch acm stars题目意思是什么 一道ACM题目,麻烦帮我解释下题意举个例子帮我说明下题意 求助一道ACM题一道很简单的ACM题目,题在这里我写的代码如下:#include using namespace std;int main(){int n,m[30];cin>>n;for(int i=0;i=0;j--){cout acm的一道c语言问题 【求助】北大acm JudgeOnline 请问谁有用C语言编写的北大acm JudgeOnline上面的题目的代码?不要求全不要有,poj1094、poj1125、poj1251、poj1915、poj1979有这五道题最好,或者一道都行啊(提供个链接都行) acm题目的a+b用c语言怎么写我写的是#includeint main(){int a,b;while(scanf(%d %d,&a,&b)==2){printf(%d ,a+b);}return 0;}他说wrong answer 一道虚拟语气的题目,Whether she be right or wrong ,she will have my unswering support... matlab 一道积分运算题目求解释用matlab计算两种方法两种答案,法1:int(0.12*x/(2.8-x),x,0,1.27273)ans =- (42*log(34391063014470689/63050394783186944))/125 - 17195599061229753/112589990684262400>> - (42*log(34391063014470689/630503 一道简单的MATLAB题目matrix=[1,3,5,9; 2,4,5,1; 9 ,8,3,1]matrix(11)的ans是什么?为什么?matrix(11)要去求的是什么? ANS=STUDENT.DBF MYFILE=SUBSTR(ANS,1,AT(.,ANS)-1) ?MYFILE 这是VFP题,小弟不懂ANS的意思,谢谢能给我讲讲这个题目么? 杭电acm 1008 题我的为什么是wrong answer 一道acm的排序题Snow_storm有n(0 一道ACM 数字统计 描述:给出一个整数n(1 英文(ACM题目)的中文翻译去哪找最好! 求解ACM题目孪生素数请用C++代码 有关ACM一道题,你的任务是计算a+b.这是为了acm初学者专门设计的题目.你肯定发现还有其他题目跟这道题的标题类似,这些问题也都是专门为初学者提供的.输入格式输入包含一系列的a和b对,通