问题 1921 --读入整数(完善程序)

1921: 读入整数(完善程序)★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 767  解决: 663
[提交][状态][命题人:]

题目描述

读入两个 int 范围内的整数, 并将这两个整数分别输出,每行一个。

#include <iostream>
using namespace std;
int readint() 
{
    int num = 0; // 存储读取到的整数
    int negative = 0; // 负数标识
    char c; // 存储当前读取到的字符
    c = cin.get();
    while ((c < '0' || c > '9') && c != '-')
        c =  _____(1)_______; 
    if (c == '-')
        negative = 1;
    else
        _____(2)_______; 
    c = cin.get();
    while ( _____(3)_______) 
	{   
        _____(4)_______
        c = cin.get();
    }
    if (negative == 1)
         _____(5)______
    return num;
}
int main() 
{
    int a, b;
    a = readint();
    b = readint();
    cout << a << endl << b << endl;
    return 0;      
}

输入

输入的整数之间和前后只会出现空格或者回车。输入数据保证合法。

输出

两个整数分别输出,每行一个

样例输入
Copy
123 -789
样例输出
Copy
123
-789

提示

来源

[提交][状态]