-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalter.c
53 lines (47 loc) · 1.17 KB
/
alter.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char bad_words[10][51];
char input[50][51];
char * output;
int compare(char*, char *);
void alter(int);
int main(){
int time;
scanf("%d", &time);
getchar();
for(int count = 0; count < time; count++){
scanf("%s", bad_words[count]);
}
output = (char *) malloc (50 * sizeof(char));
scanf("%s", output);
alter(time);
printf("%s", output);
return 0;
}
void alter(int word_count){
int current = 0;
while(*(output + current) != '\0'){
for(int count = 0; count < word_count; count++){
if(compare((output + current), bad_words[count])){
int len = strlen(bad_words[count]);
for(int c = 1; c < len; c++){
current++;
*(output + current) = '*';
}
}
}
current++;
}
}
int compare(char * origin, char * to_compare){
int len = strlen(to_compare);
int is_same = 1;
for(int count = 0; count < len; count++){
if(*(origin + count) != *(to_compare + count)){
is_same = 0;
break;
}
}
return is_same;
}