@java Blue Bridge Cup Group B Exercise Basics (30) The fifth question: Find integer

@java Blue Bridge Cup Group B Exercise Basics (30) The fifth question: Find integer

Keywords: cycling, judge

Problem Description

Comprising a given number of columns n integers, ask a first integer number of columns in the first occurrence of the first few.

Input format
The first line contains an integer n.

The second line contains a non-negative integer n, for a given number of columns, each column count is not greater than 10,000.

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

Output Format
If a number appears in the column, it is the first occurrence of the output position (position numbering begins at 1), otherwise the output -1.
Sample input
. 6
. 1. 8. 9. 4. 3. 9
. 9
sample output
2
the data size and Conventions
1 <= n <= 1000.

Code:

public class Main{
	static boolean h=true,k=false;
	public static void main(String[] args) {
		java.util.Scanner s=new java.util.Scanner(System.in);
		int q=s.nextInt();
		if(q<=1000&&q>=1){
			int pipei,weizhi=1;
			int a[]=new int[q];
			for(int i=0;i<q;i++){
				a[i]=s.nextInt();
				if(a[i]<=10000){
					continue;
				}else {
					System.out.println("数列中的每个数都不能大于10000");
					h=false;
					break;
				}
			}
			if(h){
				pipei=s.nextInt();
			for(int i=0;i<q;i++){
				if(pipei==a[i]){
					k=true;
					System.out.println(weizhi);
					break;
				}
				weizhi+=1;
			}
			if(!k){
				System.out.println(-1);
			}
			}
		}else System.out.println("数据规模与约定:1 <= n <= 1000。");
	}
}
Published 29 original articles · won praise 1 · views 1101

Guess you like

Origin blog.csdn.net/DAurora/article/details/104155280