Advertisement
AngelGiurov

Untitled

Jul 15th, 2021
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class asfg {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. String[] arraysSize = sc.nextLine().split(" ");
  7. StringBuilder sb = new StringBuilder();
  8. int sum = 0;
  9. String[] firstString = new String[Integer.parseInt(arraysSize[0])];
  10. firstString = sc.nextLine().split(" ");
  11. String[] secondString = new String[Integer.parseInt(arraysSize[1])];
  12. secondString = sc.nextLine().split(" ");
  13. boolean haveToAddAnotherOne = false;
  14. int biggerNumber = 0;
  15. int smallerNumber = 0;
  16. if (Integer.parseInt(arraysSize[0]) > Integer.parseInt(arraysSize[1])){
  17. biggerNumber = Integer.parseInt(arraysSize[0]);
  18. smallerNumber = Integer.parseInt(arraysSize[1]);
  19. }else {
  20. biggerNumber = Integer.parseInt(arraysSize[1]);
  21. smallerNumber = Integer.parseInt(arraysSize[0]);
  22. }
  23. for (int i = 0; i < biggerNumber; i++) {
  24. if (i >= firstString.length){
  25. sum = Integer.parseInt(secondString[i]);
  26. if (haveToAddAnotherOne){
  27. sum ++;
  28. haveToAddAnotherOne = false;
  29. }
  30. if (sum > 9){
  31. sum = sum % 10;
  32. haveToAddAnotherOne = true;
  33. }
  34. sb.append(sum).append(" ");
  35. sum = 0;
  36. continue;
  37. }else if (i >= secondString.length){
  38. sum = Integer.parseInt(firstString[i]);
  39. if (haveToAddAnotherOne){
  40. sum ++;
  41. haveToAddAnotherOne = false;
  42. }
  43. if (sum > 9){
  44. sum = sum % 10;
  45. haveToAddAnotherOne = true;
  46. }
  47. sb.append(sum).append(" ");
  48. sum = 0;
  49. continue;
  50. }
  51. sum = Integer.parseInt(firstString[i]) + Integer.parseInt(secondString[i]);
  52. if (haveToAddAnotherOne){
  53. sum++;
  54. haveToAddAnotherOne = false;
  55. }
  56. if (sum > 9){
  57. sum = sum % 10;
  58. haveToAddAnotherOne = true;
  59. }
  60. sb.append(sum).append(" ");
  61. sum = 0;
  62. }
  63. System.out.println(sb.toString().substring(0,sb.length() - 1));
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement