一道acm题目 报错是wrong answer
来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/14 06:13:38
一道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
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
最明显的错误,就是
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;
}
再问: 哦 超谢谢你 那程序还需要怎么改一下吗
再问: 对了 可以要你的联系方式吗 我才入门 求大神带我飞😐
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
一道ACM题目 报错wrong answer
ACM 2453 Wrong Answer
acm题,wrong answer,为什么?
acm wrong answer是由什么引起的?北邮一道简单的减法题:
acm简单的问题一直wrong answer
简单acm题,为什么会wrong answer?
acm题为什么wrong answer啊
一道ACM题目,看不懂
一道ACM题目(解释一下题意)
acm的一道题贪心的酒鬼我总是wrong answer有没有人能挑战下,代码很短.c语言
关于画矩形的acm这道题哪里错了啊?系统老是说wrong answer