Codeup 刷题解析系统
发布时间
阅读量:
阅读量
codeup的地址
题目来源:《算法笔记》
1934 找x
题目描述
给定一个整数n,随后输入n个互不相同的数值,再输入一个目标值x,要求找出该值在数组中的位置索引(索引从0开始计数),若未找到则返回-1。
输入
测试数据包含多组情况,每组首先输入n(1<=n<=200),随后输入n个数值,最后输入x。
输出
针对每组输入数据,输出对应的结果。
样例输入
4
1 2 3 4
3
样例输出
2
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 10;
int a[maxn];
int main(){
int n;
while(scanf("%d",&n) != EOF){
for(int i = 0;i < n;i++) scanf("%d",&a[i]);
int k,index;
scanf("%d",&k);
for(index = 0;index < n;index++){
if(a[index] == k){
全部评论 (0)
还没有任何评论哟~
