OJ三种循环输入

1.第一种

输入:
2
1 5
4 8
输出:
6
12

//代码
#include<vector> 
using namespace std;
int main()
{
    int t = 3;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
} 

2.第二种

输入:
1 5
2 7
2 5
.。。。。。。不确定输入多少组
输出:
6
9
7
.。。。。
代码:
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        cout<<a+b<<endl;
    }
    return 0;
} 

3.第三种高效率C语言输入

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

猜你喜欢

转载自blog.csdn.net/luoshiyong123/article/details/104776869