版权声明:转载请注明出处 https://blog.csdn.net/weixin_42981803/article/details/83279458
Problem Description
E_star由于在上次考试中取得了很好的成绩他开始骄傲起来,此时von看不下去了,于是就想找他的岔,他把E_star叫来说最近一道A+B编程题目不会,想要让同是计算机专业的E_star来帮他解答,E_star由于考试后的骄傲心理,二话没说结一口答应了,等到von用qq把题目要求发给E_star的时候他傻眼了。自己根本就不会,其实von知道他不会故意整他的。他为了留住面子只好请他最好的朋友你帮他解答了。这下知道骄傲的后果了吧。
Input
题目有多组数据,处理到文件结束。输入的第一行包含一个数T代表测试组数;
接下来有T行,每行有两个数A,B;
Output
对于每一组数据输出的第一行是"Case #:"代表第几组数据;
接下来一行是A+B=以及A+B的和。
每两个组数据之间输出一个空行。
Sample Input
2 1 2 112233445566778899 998877665544332211
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
Hint
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int t, i, j, z, x, n;
String str;
t = reader.nextInt();
reader.nextLine();
for(i=1;i<=t;i++) {
str = reader.nextLine();
System.out.println("Case "+i+":");
String[] s=str.split(" ");
char[] a=s[0].toCharArray();
char[] b=s[1].toCharArray();
int[] f=new int[10000];
n=0;
x=0;
j=a.length-1;
z=b.length-1;
System.out.print(s[0]+" + "+s[1]+" = ");
while(j>=0&&z>=0) {
x+=(a[j--]-'0')+(b[z--]-'0');
if(x>=10) {
f[n++]=x-10;
x=1;
}
else {
f[n++]=x;
x=0;
}
}
while(j>=0) {
x+=(a[j--]-'0');
if(x>=10) {
f[n++]=x-10;
x=1;
}
else {
f[n++]=x;
x=0;
}
}
while(z>=0) {
x+=(b[z--]-'0');
if(x>=10) {
f[n++]=x-10;
x=1;
}
else {
f[n++]=x;
x=0;
}
}
if(x!=0)f[n++]=x;
for(j=n-1;j>=0;j--) {
if(j==0)System.out.println(f[j]);
else System.out.print(f[j]);
}
System.out.println();
}
reader.close();
}
}