1190 -- 找x

找x

Time Limit:1000MS  Memory Limit:65536K
Total Submit:117 Accepted:58

Description

输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1)。

Input

测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x。

Output

对于每组输入,请输出结果。

Sample Input

2
1 3
0

Sample Output

-1

Source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AK1190 {
    class Program {
        static void Main(string[] args) {
            string sb;
            while ((sb = Console.ReadLine()) != null) {
                int n = int.Parse(sb);
                int[] a = new int[n];
                string[] s = Console.ReadLine().Split();
                for (int i = 0; i < n; i++) a[i] = int.Parse(s[i]);
                int x = int.Parse(Console.ReadLine());
                bool flag = true;
                for(int i=0;i<n;i++)
                    if (a[i] == x) {
                        flag = false;
                        Console.WriteLine(i);
                        break;
                    }
                if (flag) Console.WriteLine("-1");
            }
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值