-
Notifications
You must be signed in to change notification settings - Fork 1
/
16 Task C#.txt
63 lines (60 loc) · 1.78 KB
/
16 Task C#.txt
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp8
{
class Program
{
static void Main(string[] args)
{
char[] array = Console.ReadLine().ToArray();
bool flag = false;
bool swit = false;
int index = -1;
for (int i = array.Length - 2; i >= 0; i--)
{
for (int j = array.Length - 1; j > i; j--)
{
if (array[i] < array[j])
{
char x = array[i];
array[i] = array[j];
array[j] = x;
index = i + 1;
flag = true;
break;
}
}
if (flag)
{
while (!swit)
{
swit = true;
for (int counter = index; counter < array.Length - 1; counter++)
{
if (array[counter] > array[counter + 1])
{
swit = false;
char x = array[counter];
array[counter] = array[counter + 1];
array[counter + 1] = x;
}
}
}
break;
}
}
if (flag)
{
Console.WriteLine(array);
Console.ReadKey();
return;
}
Console.WriteLine(-1);
Console.ReadKey();
return;
}
}
}