7-4 寻找250 (10分)

7-4 寻找250 (10分)

在这里插入图片描述

对方不想和你说话,并向你扔了一串数…… 而你必须从这一串数字中找到“250”这个高大上的感人数字。

输入格式:

输入在一行中给出不知道多少个绝对值不超过1000的整数,其中保证至少存在一个“250”。

输出格式:

在一行中输出第一次出现的“250”是对方扔过来的第几个数字(计数从1开始)。题目保证输出的数字在整型范围内。

输入样例:

888 666 123 -233 250 13 250 -222

输出样例:

5

AC

#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    
    
	int cnt=1,x;
	while(cin>>x) {
    
    
		if(x!=250)
			cnt++;
		else {
    
    
			cout<<cnt;
			return 0;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45745322/article/details/113355264