Search for Integers

Source: Internet
Author: User

Search for Integers

Import java. io. *; public class Main {public static void main (String [] args) throws Exception {BufferedReader bf = new BufferedReader (new InputStreamReader (System. in); int a = Integer. parseInt (bf. readLine (); int B [] = new int [a]; String s [] = bf. readLine (). split (""); int c = Integer. parseInt (bf. readLine (); int number =-1; int j = 0, I = 0; for (I = 0; I <s. length; I ++) {B [I] = Integer. parseInt (s [I]) ;}for (I = 0; I <a; I ++) {if (B [I] = c) {number = I + 1; break;} System. out. println (number );}}

Problem description

Returns a series containing n integers. the first occurrence of integer a in the series is the nth.

Input Format

The first line contains an integer n.

The second row contains n non-negative integers, which are the given series. Each number in the series is not greater than 10000.

The third row contains an integer a, which is the number to be searched.

Output Format if a appears in the series, output the position where it appears for the first time (the position starts from 1); otherwise, output-1. Sample Input 6
1 9 4 8 3 9
Sample 9 output 2 data scale and Convention 1 <= n <= 1000.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.