Advertisement
Spocoman

01. Train

Jan 21st, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. Решение без масив:
  2.  
  3. using System;
  4.  
  5. namespace Train
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             string concat = string.Empty;
  13.             int sum = 0;
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 string num = Console.ReadLine();
  17.                 concat += num + ' ';
  18.                 sum += int.Parse(num);
  19.             }
  20.             Console.WriteLine(concat);
  21.             Console.WriteLine(sum);
  22.         }
  23.     }
  24. }
  25.  
  26. Решение с масив:
  27.  
  28. using System;
  29. using System.Linq;
  30.  
  31. namespace Train
  32. {
  33.     class Program
  34.     {
  35.         static void Main(string[] args)
  36.         {
  37.             int n = int.Parse(Console.ReadLine());
  38.             int[] concat = new int[n];
  39.            
  40.             for (int i = 0; i < n; i++)
  41.             {
  42.                 concat[i] = int.Parse(Console.ReadLine());
  43.             }
  44.             Console.WriteLine(string.Join(" ",concat));
  45.             Console.WriteLine(concat.Sum());
  46.         }
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement