题目(10)答案

这是一个简单的顺序查找

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int _myList[10001];
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int t;
		cin >> t;
		_myList[i] = t;
	}
	int find;
	cin >> find;
	int num;
	for(int i = 1; i <= n; i++)
	{
		if(_myList[i] == find){
			num = i;
			cout << num << endl;
			return 0;
		}
	}
	cout << "-1" << endl; 
	return 0;
}
posted @ 2020-01-21 16:51  Aeterna_Gungnir  阅读(64)  评论(0编辑  收藏  举报