Input and Output

代码人生写了关于C语言的输入输出,具体内容猛击这里。在这里,我仅对C++的输入cin输出cout做一些小小的总结。具体如下

ACM中最常见的三种输入格式(以A+B为例)

一、hdu1090
Sample Input
2
1 5
10 20

Sample Output
6
30

 

二、hdu1091
Sample Input
1 5
10 20
0 0

Sample Output
6
30 
三、hdu1089
Sample Input
1 5
10 20

Sample Output
6
30

 代码1:

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int T,a,b;
    cin >> T;
    
    for(int i=0; i<T; i++){
        cin >> a >> b;
        cout << a+b <<endl;
    }
    return 0;
}

 

代码2

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int T,a,b;
    cin >> T;
    
    while(T--)
        cin >> a >> b;
        cout << a+b <<endl;
    }
    return 0;
}

 

 代码1

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int a,b;
    
    while(cin>>a >>b){
        if(a==0 && b==0) break;
        cout << a+b <<endl;
    }
    return 0;
}

 

代码2

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int a,b;
    
    while(cin>>a >>b, a || b){
        cout << a+b <<endl;
    }
    return 0;
}

 

代码1 

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int a,b;
    
    while(cin>>a >>b){
        cout << a+b <<endl;
    }
    return 0;
}

 

 

ACM中最常见的三种输出格式

一、hdu1094 一行一输出
NOTE with one line of output for each line in input.

Sample Input
4 1 2 3 4
5 1 2 3 4 5

Sample Output
10
15
二、hdu1095
NOTE followed by a blank line.                             

Sample Input
1 5
10 20

Sample Output
6

30
三、hdu1096
NOTE there is a blank line between outputs

Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3

Sample Output
10

15

6
 
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int T, sum, a;
    
    while(cin>>T){
        sum =0;
        for(int i=0; i<T; i++){
            cin >> a;
            sum += a;
        }
        cout <<sum<<endl;
    }
    return 0;
}

 

 
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int a,b;
    
    while(cin>>a>>b){
        cout <<a+b<<endl<<endl;
    }
    return 0;
}

 

 
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    int T, n, a, sum;
    cin >>T;
    while(T--){
        cin >> n;
        sum = 0;
        for(int i=0; i<n; i++){
            cin >> a;
            sum += a;
        }
        cout << sum<<endl;
        if(T) cout <<endl;
    }
    return 0;
}

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/linspirit/articles/3786111.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值