九度OJ 1052 找x

题目链接:http://ac.jobdu.com/problem.php?pid=1052


题目分析:

将输入数据存到数组中,设置一个标志位temp判断是否找到数据。


源代码:

#include <iostream>
using namespace std;

int main()
{
	int n;
	while (cin>>n)
	{
		int a[210] = {0};
		int x;
		int temp = -1;
		for (int i = 0; i < n; i ++)
		{
			cin>>a[i];
		}
		cin>>x;
		for (int j = 0; j < n; j ++)
		{
			if (x == a[j])
			{
				temp = j;
				cout<<temp<<endl;
			}
			
		}
		if (temp == -1)
		{
			cout<<"-1"<<endl;
		}

	}

	return 0;
}


原文地址:https://www.cnblogs.com/javawebsoa/p/3085777.html