Created
February 12, 2019 15:39
-
-
Save igorLisovitskiy/d2e0e759a2e0666e1deec5b192570d08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ReadConsole | |
{ | |
class Program | |
{ | |
public static void Print1DArrayOfNumbers(int[] arr) | |
{ | |
foreach (int el in arr) | |
{ | |
Console.Write($"{el} "); | |
} | |
Console.WriteLine(); | |
} | |
public static string[] SplitBySpace(string text) { | |
string[] temp = new string[text.Length]; | |
string value = ""; | |
int count = 0; | |
for (int i = 0; i < text.Length; i++) | |
{ | |
if (text[i] != 32) | |
{ | |
value += text[i]; | |
} | |
if (text[i] == 32 && value != "" || i == text.Length -1) | |
{ | |
count++; | |
temp[i] = value; | |
value = ""; | |
} | |
} | |
string[] result = new string[count]; | |
count = 0; | |
for (int j = 0; j < temp.Length; j++) { | |
if (temp[j] != null) { | |
result[count] = temp[j]; | |
count++; | |
} | |
} | |
return result; | |
} | |
static void Main(string[] args) | |
{ | |
string result = ""; | |
while (true) | |
{ | |
string userInput = Console.ReadLine(); | |
if (userInput == "") | |
{ | |
Console.WriteLine("Done."); | |
break; | |
} | |
result += " " + userInput; | |
} | |
string[] splitInput = SplitBySpace(result); | |
int[] convertedInput = new int[splitInput.Length]; | |
for (int i = 0; i < splitInput.Length; i++) | |
{ | |
convertedInput[i] = Convert.ToInt32(splitInput[i]); | |
} | |
Console.WriteLine("Your input:"); | |
Print1DArrayOfNumbers(convertedInput); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment