-
Notifications
You must be signed in to change notification settings - Fork 0
/
searching.cpp
59 lines (51 loc) · 657 Bytes
/
searching.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
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main(int argc, char *argv[])
{
char s[100];
int si=0, k=0, ai=0, i, x;
int len = strlen(argv[1]), flag=0;
for(i=0;i<len;i++)
{
if(argv[1][i] == ' ')
{
k++;
continue;
}
}
k++;
int a[k];
for(i=0;i<len;i++)
{
if(argv[1][i] == ' ')
{
s[si] = '\0';
x = atoi(s);
a[ai] = x;
ai++;
si=0;
continue;
}
s[si] =argv[1][i];
si++;
}
s[si] ='\0';
x= atoi(s);
a[ai] = x;
ai++;
//searching
int key = atoi(argv[2]);
for(i=0;i<k;i++)
{
if(a[i] == key){
cout<<i+1<<endl;
flag=1;
break;
}
}
if(flag==0)
cout<<"0"<<endl;
return 0;
}