-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (38 loc) · 1.24 KB
/
Program.cs
File metadata and controls
51 lines (38 loc) · 1.24 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
using System;
namespace Bigger_is_Greater {
class Program {
public static string BiggerIsGreater(string w) {
int wLength = w.Length;
if (wLength == 1)return "no answer";
char[] wCharArray = w.ToCharArray();
int i = wLength - 1;
while (i > 0 && wCharArray[i - 1] >= wCharArray[i]) {
i--;
}
if (i <= 0)return "no answer";
int j = wLength - 1;
while (wCharArray[j] <= wCharArray[i - 1]) {
j--;
}
char temp = wCharArray[i - 1];
wCharArray[i - 1] = wCharArray[j];
wCharArray[j] = temp;
j = wLength - 1;
while (i < j) {
char temp2 = wCharArray[i];
wCharArray[i] = wCharArray[j];
wCharArray[j] = temp2;
i++;
j--;
}
return new string(wCharArray);
}
static void Main(string[] args) {
int T = Convert.ToInt32(Console.ReadLine().Trim());
for (int i = 0; i < T; i++) {
string w = Console.ReadLine();
Console.WriteLine(BiggerIsGreater(w));
}
}
}
}