Task: | ModAdd |
Sender: | david.meichel |
Submission time: | 2018-09-22 14:31:28 +0300 |
Language: | Java |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.15 s | details |
#2 | ACCEPTED | 0.42 s | details |
#3 | ACCEPTED | 0.43 s | details |
#4 | ACCEPTED | 0.40 s | details |
#5 | ACCEPTED | 0.40 s | details |
#6 | ACCEPTED | 0.40 s | details |
#7 | ACCEPTED | 0.43 s | details |
#8 | ACCEPTED | 0.35 s | details |
#9 | ACCEPTED | 0.42 s | details |
#10 | ACCEPTED | 0.29 s | details |
Code
import java.util.*; import java.io.*; public class Task1 { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line1 = reader.readLine(); String line2 = reader.readLine(); if (line1.length() < line2.length()) { String tmp = line1; line1 = line2; line2 = tmp; } int[] a = new int [line1.length()]; for (int i = 0; i < line1.length(); i++) { a[i] = line1.charAt(i) - '0'; } int[] b = new int[line2.length()]; for (int i = 0; i < line2.length(); i++) { b[i] = line2.charAt(i) - '0'; } int[] result = new int[line1.length()]; int a_length = a.length; int b_length = b.length; for (int i = 1; i <= line2.length() ;i++ ) { int r = a[a_length-i]+b[b_length-i]; if (r >= 10) { r -= 10; } // end of if result[result.length-i] = r; } // end of for for (int i = 1;i <= a.length - b.length ;i++ ) { int r = a[a_length-b_length-i]; result[result.length-b_length-i] = r; } // end of for print_array(result); } public static void print_array(int[] a) { boolean b = true; boolean zeros = false; StringBuffer buffer = new StringBuffer(""); for (int i = 0;i < a.length ;i ++ ) { if (a[i] != 0 || zeros) { b = false; zeros = true; buffer.append(a[i]);//System.out.print(a[i]); } } if (b) { System.out.print("0"); } else System.out.print(buffer); } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
3797629225 9766508989 |
correct output |
---|
2453127104 |
user output |
---|
2453127104 |
Test 2
Verdict: ACCEPTED
input |
---|
552139016901047883384892240490... |
correct output |
---|
552139016901047883384892240490... |
user output |
---|
552139016901047883384892240490... |
Test 3
Verdict: ACCEPTED
input |
---|
860793811134668093345482099582... |
correct output |
---|
487710306894083216377653715430... |
user output |
---|
487710306894083216377653715430... |
Test 4
Verdict: ACCEPTED
input |
---|
2 870841652294197226626825161089... |
correct output |
---|
870841652294197226626825161089... |
user output |
---|
870841652294197226626825161089... |
Test 5
Verdict: ACCEPTED
input |
---|
0 404905566051213252279994991040... |
correct output |
---|
404905566051213252279994991040... |
user output |
---|
404905566051213252279994991040... |
Test 6
Verdict: ACCEPTED
input |
---|
430112167406460960088878635088... |
correct output |
---|
430112167406460960088878635088... |
user output |
---|
430112167406460960088878635088... |
Test 7
Verdict: ACCEPTED
input |
---|
867016005819001635643395991596... |
correct output |
---|
999999999999999999999999999999... |
user output |
---|
999999999999999999999999999999... |
Test 8
Verdict: ACCEPTED
input |
---|
120453771521975552204976752778... |
correct output |
---|
0 |
user output |
---|
0 |
Test 9
Verdict: ACCEPTED
input |
---|
239979749009277805816504910098... |
correct output |
---|
239979749009277805816504910098... |
user output |
---|
239979749009277805816504910098... |
Test 10
Verdict: ACCEPTED
input |
---|
990963963634143754324162574923... |
correct output |
---|
818540385713473048971388312665... |
user output |
---|
818540385713473048971388312665... |