第10课。
This commit is contained in:
32
10/Exercise01.c
Normal file
32
10/Exercise01.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
bool compareChar(char examinee, char pattern) {
|
||||
if(pattern == '?' || pattern == examinee) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int index = 0, shift = 0;
|
||||
bool same = false;
|
||||
char sA[31] = {0}, sB[31] = {0};
|
||||
scanf("%s", sA);
|
||||
scanf("%s", sB);
|
||||
for (index = 0; index <= strlen(sA) - strlen(sB); index++) {
|
||||
same = true;
|
||||
for (shift = 0 ; shift < strlen(sB) && same; shift++) {
|
||||
if (!compareChar(sA[index+shift], sB[shift])) {
|
||||
same = false;
|
||||
}
|
||||
}
|
||||
if (same) {
|
||||
printf("%d ", index);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user