【HUSTOJ】1077: 数组元素的查找

来源:互联网 发布:阿里云开放3306端口 编辑:程序博客网 时间:2024/06/06 05:54

1077: 数组元素的查找

Time Limit: 1 Sec  Memory Limit: 128 MB

Submit: 53  Solved: 39

原题链接

Description

给你m个整数,查找其中有无值为n的数,有则输出该数第一次出现的位置,没有则输出-1。

Input

第一行一个整数m:数的个数 ( 0 <= m <= 100 ) 第二行m个整数(空格隔开)( 这些数在 0-999999范围内 ) 第三行为要查找的数n

Output

n的位置或-1

Sample Input

41 2 3 33

Sample Output

3

HINT

Source


#include<iostream>using namespace std;main(){int m,n,a[100],count=0;cin>>m;for(int i=0;i<m;i++){cin>>a[i];}cin>>n;for(int j=0;j<m;j++){if(a[j]==n){cout<<j+1<<endl;break;    }    else {count++;}}if(count==m){cout<<-1<<endl;}}


0 0
原创粉丝点击