acm之奇葩数据输入专题

1.每組测试数据都在一行,不知道每组测试数据的长度,以换行为测试数据输入的结束

关键代码:if (cin.get() == '\n')   {语句}

例如:找出每组测试的最大值:

输入:

3 1 4 2  3

5 1 4 2 -1 6

输出:

4

6

代码:

#include<iostream>
using namespace std;
#define inf  -922337
int main()
{
    int max=inf;
    int t;
    while(cin>>t)
    {
        if(t>max)
        max=t;
        if(cin.get()=='\n')
        {
        cout<<max<<endl;
        max=inf;
        }
    }
}
View Code

猜你喜欢

转载自www.cnblogs.com/Aiahtwo/p/10479625.html