Last active
August 25, 2017 18:09
-
-
Save axayjha/a96c260ea7e33f1c8a147d8ab97d083f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int find(int, int); | |
int main() | |
{ | |
int n, k; | |
scanf("%d %d", &n, &k); | |
int c = find(n,k); | |
printf("%d\n", c); | |
} | |
int find(int n, int k) | |
{ | |
int number, i=0, count=0, index=-1; | |
while(scanf(" %d", &number) && number!=-1) | |
{ | |
if(number==n) | |
{ | |
index=i; | |
if(++count ==k) break; | |
} | |
i++; | |
} | |
if (count!=k) return -1; | |
return index; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment