Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class asfg {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] arraysSize = sc.nextLine().split(" ");
- StringBuilder sb = new StringBuilder();
- int sum = 0;
- String[] firstString = new String[Integer.parseInt(arraysSize[0])];
- firstString = sc.nextLine().split(" ");
- String[] secondString = new String[Integer.parseInt(arraysSize[1])];
- secondString = sc.nextLine().split(" ");
- boolean haveToAddAnotherOne = false;
- int biggerNumber = 0;
- int smallerNumber = 0;
- if (Integer.parseInt(arraysSize[0]) > Integer.parseInt(arraysSize[1])){
- biggerNumber = Integer.parseInt(arraysSize[0]);
- smallerNumber = Integer.parseInt(arraysSize[1]);
- }else {
- biggerNumber = Integer.parseInt(arraysSize[1]);
- smallerNumber = Integer.parseInt(arraysSize[0]);
- }
- for (int i = 0; i < biggerNumber; i++) {
- if (i >= firstString.length){
- sum = Integer.parseInt(secondString[i]);
- if (haveToAddAnotherOne){
- sum ++;
- haveToAddAnotherOne = false;
- }
- if (sum > 9){
- sum = sum % 10;
- haveToAddAnotherOne = true;
- }
- sb.append(sum).append(" ");
- sum = 0;
- continue;
- }else if (i >= secondString.length){
- sum = Integer.parseInt(firstString[i]);
- if (haveToAddAnotherOne){
- sum ++;
- haveToAddAnotherOne = false;
- }
- if (sum > 9){
- sum = sum % 10;
- haveToAddAnotherOne = true;
- }
- sb.append(sum).append(" ");
- sum = 0;
- continue;
- }
- sum = Integer.parseInt(firstString[i]) + Integer.parseInt(secondString[i]);
- if (haveToAddAnotherOne){
- sum++;
- haveToAddAnotherOne = false;
- }
- if (sum > 9){
- sum = sum % 10;
- haveToAddAnotherOne = true;
- }
- sb.append(sum).append(" ");
- sum = 0;
- }
- System.out.println(sb.toString().substring(0,sb.length() - 1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement