forked from NataSola/HelloCode
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathProgram.cs
More file actions
153 lines (123 loc) · 3.38 KB
/
Copy pathProgram.cs
File metadata and controls
153 lines (123 loc) · 3.38 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// // // Вид 1. Описание
void Method1()
{
Console.WriteLine("Автор ...");
}
// Вызов
Method1();
// // // Вид2. Описание
void Method2(string msg)
{
Console.WriteLine(msg);
}
// Вызов
Method2(msg: "Текст сообщения");
// Описание
void Method21(string msg, int count)
{
int i = 0;
while (i < count)
{
Console.WriteLine(msg);
i++;
}
}
// Вызов
Method21(msg: "Текст", count: 4);
Method21(count: 4, msg: "новый текст");
// // // Вид 3. Описание
int Method3()
{
return DateTime.Now.Year;
}
// Вызов
int year = Method3();
//Console.WriteLine(year);
// // // Вид4. Описание
// string Method4(int count, string text)
// {
// int i = 0;
// string result = String.Empty;
// while (i < count)
// {
// result = result + text;
// i++;
// }
// return result;
// }
string Method4(int count, string text)
{
string result = String.Empty;
for (int i = 0; i < count; i++)
{
result = result + text;
}
return result;
}
string res = Method4(10, "z");
Console.WriteLine(res);
//for
// // // for (int i = 2; i <= 10; i++)
// // // {
// // // for (int j = 2; j <= 10; j++)
// // // {
// // // Console.WriteLine($"{i} x {j} = {i * j}");
// // // }
// // // Console.WriteLine();
// // // }
// // // Работа с текстом
// // // string s = "qwerty"
// // // 012
// // // s[3] // r
// // // Дан текст. В тексте нужно все пробелы заменить черточками,
// // // маленькие буквы “к” заменить большими “К”,
// // // a большие “С” заменить маленькими “с”.
// // // Ясна ли задача?
string text = "— Я думаю, — сказал князь, улыбаясь, — что, "
+ "ежели бы вас послали вместо нашего милого Винценгероде,"
+ "вы бы взяли приступом согласие прусского короля. "
+ "Вы так красноречивы. Вы дадите мне чаю?";
string Replace(string text, char oldValue, char newValue)
{
string result = String.Empty;
int length = text.Length;
for (int i = 0; i < length; i++)
{
if(text[i] == oldValue) result = result + $"{newValue}";
else result = result + $"{text[i]}";
}
return result;
}
string newText = Replace(text, ' ', '|');
Console.WriteLine(newText);
Console.WriteLine();
newText = Replace(newText, 'к', 'К');
Console.WriteLine(newText);
// Сортировка одномерного массива
int[] arr = { 1, 5, 4, 3, 2, 6, 7, 1, 1 };
void PrintArray(int[] array)
{
int count = array.Length;
for (int i = 0; i < count; i++)
{
Console.Write($"{array[i]} ");
}
Console.WriteLine();
}
void SelectionSort(int[] array)
{
for (int i = 0; i < array.Length - 1 ; i++)
{
int minPosition = i;
for (int j = i + 1; j < array.Length; j++)
{
if(array[j] < array[minPosition]) minPosition = j;
}
int temporary = array[i];
array[i] = array[minPosition];
array[minPosition] = temporary;
}
}
PrintArray(arr);
SelectionSort(arr);
PrintArray(arr);