acm 1002 老是Presentation Error 高手解决一下!
packageone;importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[]args)...
package one;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n,j=1;
String a, b;
char[] a1, b1;
int[] sum1, a2, b2;
Scanner in = new Scanner(System.in);
n = in.nextInt();
while ((n--) > 0) {
a = in.next();
b = in.next();
int maxlen = a.length() > b.length() ? a.length() : b.length();
a1 = new char[a.length()];
b1 = new char[b.length()];
a2 = new int[maxlen];
b2 = new int[maxlen];
a.getChars(0, a.length(), a1, 0);
b.getChars(0, b.length(), b1, 0);
sum1 = new int[maxlen + 1];
System.out.println("Case "+(j++)+":");
System.out.print(new String(a1)+" + "+new String(b1)+" = ");
a1 = renew(a1);
b1 = renew(b1);
for (int i = 0; i < maxlen; i++) {
if (i < a1.length) {
a2[i] = a1[i] - '0';
}else {
a2[i]=0;
}
}
for (int i = 0; i < maxlen; i++) {
if (i < b1.length) {
b2[i] = b1[i] - '0';
}else {
b2[i]=0;
}
}
sum1 = new int[maxlen + 1];
for (int i = 0; i < maxlen; i++) {
sum1[i] = 0;
}
for (int i = 0; i < maxlen; i++) {
sum1[i] = sum1[i] + a2[i] + b2[i];
if (sum1[i] >= 10) {
sum1[i] = sum1[i] % 10;
sum1[i + 1] = 1;
}
}
if(sum1[maxlen]==0)
{
maxlen=maxlen-1;
}
for (int i = 0; i < maxlen + 1; i++) {
System.out.print(sum1[maxlen-i]);
}
System.out.print("\n"+"\n");
}
}
public static char[] renew(char[] old) {
char[] newly = new char[old.length];
for (int i = 0; i < old.length; i++) {
newly[i] = old[old.length - i - 1];
}
return newly;
}
} 展开
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n,j=1;
String a, b;
char[] a1, b1;
int[] sum1, a2, b2;
Scanner in = new Scanner(System.in);
n = in.nextInt();
while ((n--) > 0) {
a = in.next();
b = in.next();
int maxlen = a.length() > b.length() ? a.length() : b.length();
a1 = new char[a.length()];
b1 = new char[b.length()];
a2 = new int[maxlen];
b2 = new int[maxlen];
a.getChars(0, a.length(), a1, 0);
b.getChars(0, b.length(), b1, 0);
sum1 = new int[maxlen + 1];
System.out.println("Case "+(j++)+":");
System.out.print(new String(a1)+" + "+new String(b1)+" = ");
a1 = renew(a1);
b1 = renew(b1);
for (int i = 0; i < maxlen; i++) {
if (i < a1.length) {
a2[i] = a1[i] - '0';
}else {
a2[i]=0;
}
}
for (int i = 0; i < maxlen; i++) {
if (i < b1.length) {
b2[i] = b1[i] - '0';
}else {
b2[i]=0;
}
}
sum1 = new int[maxlen + 1];
for (int i = 0; i < maxlen; i++) {
sum1[i] = 0;
}
for (int i = 0; i < maxlen; i++) {
sum1[i] = sum1[i] + a2[i] + b2[i];
if (sum1[i] >= 10) {
sum1[i] = sum1[i] % 10;
sum1[i + 1] = 1;
}
}
if(sum1[maxlen]==0)
{
maxlen=maxlen-1;
}
for (int i = 0; i < maxlen + 1; i++) {
System.out.print(sum1[maxlen-i]);
}
System.out.print("\n"+"\n");
}
}
public static char[] renew(char[] old) {
char[] newly = new char[old.length];
for (int i = 0; i < old.length; i++) {
newly[i] = old[old.length - i - 1];
}
return newly;
}
} 展开
1个回答
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32F103是一款高性能的嵌入式芯片,由意法半导体(STMicroelectronics)公司生产。它是STM32系列芯片之一,具有紧凑、低功耗、高性能等特点,被广泛应用于嵌入式系统中。STM32F103的主要特点包括:1. 集成了A...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询