时间限制
400 ms
内存限制
64 MB
题目描述:
对方不想和你说话,并向你扔了一串数…… 而你必须从这一串数字中找到“250”这个高大上的感人数字。
输入格式:
输入在一行中给出不知道多少个绝对值不超过1000的整数,其中保证至少存在一个“250”。
输出格式:
在一行中输出第一次出现的“250”是对方扔过来的第几个数字(计数从1开始)。题目保证输出的数字在整型范围内。
输入样例:
888 666 123 -233 250 13 250 -222
输出样例:
5
给定一些数字 找出第一个250的出现位置
emmmmmmm
用pos去记录是否已经找到250的位置并存储位置了
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int pos = -1;
int n = 0;
while (sc.hasNext())
{
int x = sc.nextInt();
n++;
if (x == 250 && pos == -1)
pos = n;
}
out.println(pos);
out.flush();
out.close();
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
}
如果有说错的 或者 不懂的 尽管提 嘻嘻
一起进步!!!