Advertisement
MeliDragon

Untitled

Mar 7th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Diagnostics.Tracing;
  5. using System.Linq;
  6. using System.Text;
  7. namespace BigNumbers
  8. {
  9. internal class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] length = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14. string inputOne = Console.ReadLine();
  15. string inputTwo = Console.ReadLine();
  16.  
  17. int n = 0;
  18. int m = 0;
  19. if (length[0] > length[1])
  20. {
  21. n = length[0];
  22. m = length[1];
  23. }
  24. else
  25. {
  26. n = length[1];
  27. m = length[0];
  28. string temp = inputOne;
  29. inputOne = inputTwo;
  30. inputTwo = temp;
  31. }
  32. int[] first = inputOne.Split(' ').Select(int.Parse).ToArray();
  33. int[] second = inputTwo.Split(' ').Select(int.Parse).ToArray();
  34. List<int> result = new List<int>();
  35. int left = 0;
  36. int sum = 0;
  37. for (int i = 0; i < n; i++)
  38. {
  39. if (i<m)
  40. {
  41. sum += first[i] + second[i];
  42. if (sum>9)
  43. {
  44. string num = sum.ToString();
  45. left = int.Parse(num[0].ToString());
  46. sum = sum % 10;
  47. }
  48. result.Add(sum);
  49. sum = 0;
  50. }
  51. else
  52. {
  53. sum = first[i];
  54. result.Add(sum);
  55. }
  56. if (left >1)
  57. {
  58. sum= left;
  59. left = 0;
  60. }
  61. if (i == n-1 && left > 1)
  62. {
  63. result.Add(left);
  64. }
  65. }
  66.  
  67. Console.WriteLine(String.Join(" ",result));
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement