-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlogic.cpp
65 lines (62 loc) · 1.4 KB
/
logic.cpp
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
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
int binSearch(int arr[], int x, int l, int r) {
int mid = (l + r)/2;
if (l > r) {
return -1;
}
if (x == arr[mid]){
return mid;
}
if (x < arr[mid]) {
return binSearch(arr, x, l, mid - 1);
} else {
return binSearch(arr, x, mid + 1, r);
}
}
int binSearch(char arr[], char x, int l, int r) {
int mid = (l + r)/2;
if (l > r) {
return -1;
}
if (x == arr[mid]){
return mid;
}
if (x < arr[mid]) {
return binSearch(arr, x, l, mid - 1);
} else {
return binSearch(arr, x, mid + 1, r);
}
}
int main(){
cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int l, m, n;
cin >> l >> m >> n;
int b[m], c[n];
char a[l];
for (int i = 0; i < l; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
cin >> c[i];
}
int q, r;
char p;
cin >> p >> q >> r;
int ap = binSearch(a, p, 0, l-1);
int aq = binSearch(b, q, 0, m-1);
int ar = binSearch(c, r, 0, n-1);
if (ap == -1 or aq == -1 or ar ==-1) {
cout << "DOST HI SAANP HAI\n";
} else {
cout << "SNAKE FOUND\n";
}
}
return 0;
}