-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path146.c
63 lines (54 loc) · 1.25 KB
/
146.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char ascii[0x7F];
int main(int argc, char const *argv[])
{
char line[0xFF];
int line_len, pos;
char min;
char *p, *p_start;
while(fgets(line, 0xFF, stdin))
{
if(line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';
if(strcmp(line, "#") == 0)
break;
line_len = strlen(line);
memset(ascii, 0, sizeof(char) * 0x7F);
p_start = &line[0];
p = p_start + line_len - 1;
while((--p) >= p_start && *p >= *(p+1))
;
if((p + 1) == p_start)
{
printf("%s\n", "No Successor");
continue;
}
p_start = p;
for (; *p; ++p)
++ascii[*p];
p = p_start;
for(pos = *p + 1; pos < 0x7F; ++pos)
{
if(ascii[pos] != 0)
{
*p = pos;
++p;
--ascii[pos];
break;
}
}
for(pos = 'A'; pos < 0x7F; ++pos)
{
while(ascii[pos] > 0)
{
*p = pos;
++p;
--ascii[pos];
}
}
printf("%s\n", line);
}
return 0;
}