-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathp442.c
45 lines (44 loc) · 1.41 KB
/
p442.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
/* Camellos, serpientes y kebabs */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char in[21], _case[21];
int i;
while(scanf("%s %s", in, _case) != EOF) {
for(i = 0; i < strlen(in); i++) {
if(strcmp(_case, "CamelCase") == 0) {
if(i == 0) {
printf("%c", toupper(in[i]));
} else if(in[i] == '-' || in[i] == '_') {
i++;
printf("%c", toupper(in[i]));
} else {
printf("%c", in[i]);
}
} else if(strcmp(_case, "snake_case") == 0) {
if(i == 0) {
printf("%c", tolower(in[i]));
} else if(in[i] == '-') {
printf("_");
} else if(in[i] == toupper(in[i]) && in[i] != '_') {
printf("_%c", tolower(in[i]));
} else {
printf("%c", in[i]);
}
} else {
if(i == 0) {
printf("%c", tolower(in[i]));
} else if(in[i] == '_') {
printf("-");
} else if(in[i] == toupper(in[i]) && in[i] != '-') {
printf("-%c", tolower(in[i]));
} else {
printf("%c", in[i]);
}
}
}
printf("\n");
}
return 0;
}