-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode.c
50 lines (45 loc) · 1.18 KB
/
decode.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
#include <stdio.h>
void decode(char *);
int getNum(char *);
int main(){
char input[105];
scanf("%s", input);
decode(input);
return 0;
}
void decode(char * input){
int current = 0;
int skip = 1;
while(*(input + current) != '\0'){
if(*(input + current) <= '9' && *(input + current) >= '0'){
int time = getNum(input + current);
if(time <= 7){
for(int count = 1; count < time; count++){
putchar(*(input + current - 1));
}
} else {
int real_time = time % 7;
for(int count = 0; count < real_time; count++){
putchar(*(input + current - 1));
}
}
while(time / 10 != 0){
skip++;
time /= 10;
}
} else {
putchar(*(input + current));
}
current += skip;
skip = 1;
}
}
int getNum(char * section){
int result = 0;
int current = 0;
while(*(section + current) >= '0' && *(section + current) <= '9'){
result = result * 10 + *(section + current) - '0';
current++;
}
return result;
}