SP1 TEST - Life, the Universe, and Everything题解

题目传送门

题意翻译

从输入读取数字并输出,每行一个,直到读到42停止。

题目描述

Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely… rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

个人理解

这道题用while循环可以解决了。while判断这个数是不是42,如果不是,输出,如果是,那么就停止。

程序

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int num;
    while(scanf("%d", &num)!=EOF&&num!=42)
    {
        printf("%d\n", num);
    }
    while(scanf("%d", &num)!=EOF);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/yingyouyu/article/details/88033876
SP1