day2--Primary Arithmetic(小学生算术-JAVA)

Primary Arithmetic(小学生算术)


看到这道题,第一眼,窃喜。然并。。。。。被坑了一天了。。。
我也不知道怎么回事。。。在洛谷OJ总是不过,一气之下去ACM上搜了一下,刚好有这题,复制提交。。。结果如下图,真的是气死我了。。让我对洛谷产生了深深的怀疑
在这里插入图片描述
然后我的算法很LOW,给你们看一下对比
在这里插入图片描述
差别很大,哎呀呀。但是我真的懒得去重新捡起C了。


切入正题

题目描述

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.

Input

Each line of input contains two unsigned integers less than 10 digits. The last line of input contains ‘0 0’.

Output

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

Sample Output

No carry operation.
3 carry operations.
1 carry operation.

大写的注意

请睁大眼睛观察输出的单复数哟。

java 代码实现

import java.util.Scanner;

public class Primary_Arithmetic {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);		
		while(sc.hasNextLine()){
			String str = sc.nextLine();
			String[] num = str.split(" ");
			int[] str_int = new int[num.length];
			int a=0,b=0;
			for(int i=0; i<str_int.length;i++){
				str_int[i]= Integer.parseInt(num[i]);
				a = str_int[0];
				b = str_int[1];
			}
			if(a==0 && b==0){
				break;
			}
			int carry = 0, count = 0;
			while(a != 0 || b != 0){
				carry = (a % 10 + b % 10 +carry) > 9 ? 1 : 0;
				count += carry;
				a /= 10;
				b /= 10;
			}
			if(count ==0){
				System.out.println("No carry operation.");
			}
			else if(count == 1){
				System.out.println("1 carry operation.");
			}
			else{
				System.out.println("" + count + " carry operations.");
			}
		}
	}

}

再见了朋友,要是发现我为什么在OJ不过的原因,请一定一定一定要告诉我!!!!ありがとうございます。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值