-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1078.c
60 lines (55 loc) · 1.12 KB
/
1078.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
#include<stdio.h>
#include<ctype.h>
void Compress();
void Decompress();
int main()
{
char sign;
scanf("%c", &sign);
getchar();
if(sign == 'C'){
Compress();
}else{
Decompress();
}
return 0;
}
void Compress(){
char prev = getchar(), input;
int cnt = 1;
while((input = getchar())){
if(input == prev){
cnt++;
}else{
if(cnt == 1){
printf("%c", prev);
}else{
printf("%d%c", cnt, prev);
}
if(input == '\n'){
break;
}
prev = input;
cnt = 1;
}
}
}
void Decompress(){
char input;
while((input = getchar())){
if(isdigit(input)){
int cnt = input - '0';
char output;
while(isdigit((output = getchar()))){
cnt = cnt * 10 + output - '0';
}
for(int i = 0; i < cnt; i++){
printf("%c", output);
}
}else if(input == '\n'){
break;
}else{
printf("%c", input);
}
}
}