本題要求從輸入的N個整數中查找給定的X。如果找到,輸出X的位置(從0開始數);如果沒有找到,輸出“Not Found”。
輸入格式:
輸入在第1行中給出2個正整數N(<=20)和X,第2行給出N個整數。數字均不超過長整型,其間以空格分隔。
輸出格式:
在一行中輸出X的位置,或者“Not Found”。
輸入樣例1:
5 7
3 5 7 1 9
輸出樣例1:
2
輸入樣例2:
5 7
3 5 8 1 9
輸出樣例2:
Not Found
#include<stdio.h>
int main(){
int a[21];
int n,x,count=0;
scanf("%d %d",&n,&x);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++){
if(x!=a[i])
count++;
else
printf("%d",i);
}
if(count==n)
printf("Not Found");
return 0;
}