import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s1=scanner.next(),s2=scanner.next(); int a=s1.length(),b=s2.length(); if(a<b){ int temp=a; a=b; b=temp; } int tf=0; int A[]=new int[a], B[]=new int[a],C[]=new int[a+1]; for (int i = 0; i < a-b; i++) { if(s1.length()<s2.length()) { A[i]=0; tf=1; } if(s1.length()>s2.length()) { B[i]=0; tf=-1; } } if(tf==-1) { for (int i = 0; i < a; i++) A[i]=s1.charAt(i)-'0'; for (int i = a-b,j=0; i < a; i++,j++) B[i]=s2.charAt(j)-'0'; } else{ for (int i = 0; i < a; i++) B[i]=s2.charAt(i)-'0'; for (int i = a-b,j=0; i < a; i++,j++) A[i]=s1.charAt(j)-'0'; } C[0]=0; for (int i = 0,j=1; i < a; i++,j++) { int temp=A[i]+B[i]%10; if(temp>=10){ C[j]=temp%10; C[j-1]+=1; } else C[j]=temp; } for (int j = 0; j < C.length; j++) for (int i = 0; i < C.length; i++) { if(C[i]>=10) { C[i]=C[i]%10; C[i-1]+=1; } } int c=0; if(C[0]==0) c=1; for (int i = c; i <C.length; i++) System.out.print(C[i]); } }
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题12.6 (C语言代码)浏览:816 |
川哥的吩咐 (C语言代码)浏览:926 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1914 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:597 |
妹子杀手的故事 (C语言代码)浏览:737 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:610 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:783 |
蛇行矩阵 (C语言代码)浏览:606 |
1124题解浏览:630 |
1126题解浏览:649 |