Skip to content

Commit 6095607

Browse files
committed
Added Solution - GfG to GitHub
1 parent 882f24a commit 6095607

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//{ Driver Code Starts
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
6+
// } Driver Code Ends
7+
class Solution {
8+
public:
9+
// Function to find element in sorted array
10+
// arr: input array
11+
// k: element to be searched
12+
bool searchInSorted(vector<int>& arr, int k) {
13+
14+
for(int i=0;i<arr.size();i++){
15+
if(arr[i]==k){
16+
return true;
17+
}
18+
}
19+
return false;
20+
}
21+
};
22+
23+
//{ Driver Code Starts.
24+
25+
int main(void) {
26+
27+
int t;
28+
cin >> t;
29+
cin.ignore();
30+
while (t--) {
31+
32+
vector<int> arr;
33+
string input;
34+
getline(cin, input);
35+
stringstream ss(input);
36+
int number;
37+
while (ss >> number) {
38+
arr.push_back(number);
39+
}
40+
41+
int k;
42+
cin >> k;
43+
cin.ignore();
44+
Solution ob;
45+
cout << (ob.searchInSorted(arr, k) ? "true" : "false") << endl;
46+
cout << "~" << endl;
47+
}
48+
49+
return 0;
50+
}
51+
52+
// } Driver Code Ends

0 commit comments

Comments
 (0)