forked from BitsPleaseMSI/BitsPlease-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
20.c
48 lines (47 loc) · 722 Bytes
/
20.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
#include <stdio.h>
#include <string.h>
#define MAXSIZE 25
int main(void) {
int N, i, j, flag=0, pos=-1, len;
char S[MAXSIZE], ch;
scanf("%d", &N);
while(N>0) {
scanf("%s %c", &S, &ch);
len=strlen(S);
for(i=0; i<len; i++) {
if(ch==S[i]) {
flag=1;
pos=i+1;
break;
}
}
if(flag==1) {
for(i=pos-1; i<len; i++) {
if(ch==S[i]) {
flag=2;
break;
}
}
if(flag==2) {
for(i=len, j=0; i>0; i--, j++) {
if(ch==S[i]) {
i-=1;
break;
}
}
for(; i>0; i--, j++) {
if(ch==S[i]) {
pos=j+1;
break;
}
}
printf("%d\n", pos);
}
else printf("%d\n", pos);
}
else printf("%d\n", pos);
N--;
pos=-1;
}
return 0;
}