The user enters two numbers separated by spaces. How can they be divided and sent to different arrays? For example, input: 23 78; The number 23 is sent to the array number 1, the number 78 is sent to the array number 2

  • What does "sent" mean? - VladD
  • Well, it is roughly written, differently like this: massiv1 [i] = 23; massive2 [i] = 78; - ZOOM SMASH

1 answer 1

Simply splitting the input into numbers:

var inputLine = Console.ReadLine(); var parts = inputLine.Split(); var numbers = parts.Select(int.Parse).ToList(); 

Now you have a list of two (ideally) numbers, contact them by index, and put where you want:

 a1[i] = numbers[0]; a2[i] = numbers[1]; 

Please note that the user may well enter from the keyboard not necessarily two and not necessarily numbers. If you need to catch this case and do something meaningful, you will need additional logic in the code.

  • This is what I am examining the Olympiad tasks, they are unlikely to enter letters there) - ZOOM SMASH
  • @ZOOMSMASH: Ah, yes, if there is an olympiad task, there is no need to check the input format. - VladD
  • Many thanks for the help - ZOOM SMASH
  • @ZOOMSMASH: Please! - VladD