-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
56 lines (52 loc) · 1.8 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
class SmallTask
{
static int MaxSymbolsInTheString = 3;
static void fillArrayFromCmd(string[] array, int size){
for (int i = 0; i < size; i++) {
Console.Write($"Array [{i}] = ");
array[i] = Console.ReadLine() ?? string.Empty;
}
}
static int fillResulArray(string[] initialArray, string[] resultArray) {
int index = 0;
for (int i = 0; i < initialArray.Length; i++) {
if (initialArray[i].Length < MaxSymbolsInTheString + 1) {
resultArray[index] = initialArray[i];
index++;
}
}
return index;
}
// Print first N (n = index) elements of array
static void printArrayToIndex(string[] array, int index) {
Console.Write("[");
for(int j = 0; j < index; j++)
{
Console.Write($"\"{array[j]}\"");
if (j < index - 1)
Console.Write(", ");
}
Console.Write("]");
}
static void Main()
{
int count = 0;
Console.Write("Enter the array size: ");
string? CountString = Console.ReadLine();
if (Int32.TryParse(CountString, out count) && count > 0) {
string[] InitialArray = new string[count];
string[] ResultArray = new string[count];
fillArrayFromCmd(InitialArray, count);
int index = fillResulArray(InitialArray, ResultArray);
Console.Clear();
printArrayToIndex(InitialArray, InitialArray.Length);
Console.Write(" -> ");
printArrayToIndex(ResultArray, index);
Console.WriteLine();
}
else {
Console.WriteLine("Error: array size is not valid");
}
}
}