OJ ACM模式输入代码模板

ACM模式不同于核心代码模式,核心代码模式只需要补充缺失代码即可,程序自动进行读取和输出。ACM模式连导入头文件都需要自己写,包括输入输出都需要自己写。
1.单行m个输入

#include <iostream>
using namespace std;
int a, b;//定义m个变量
int main1() {
    cin >> a >> b;
    cout << "当前输入:a:" << a << "   b:"  << b << endl;
}

2.n行m个输入

#include <iostream>
using namespace std;
int main2(){//只进行一次n行数据的输入
    int n, a, b;
    cin >> n;
    while (n --){
        cin >> a >> b;
        cout << "a:" << a << "   b:" << b << endl;
    }
}
int main3(){//循环读取输入的n值,程序不结束
    int n, a, b;
    while(cin >> n){
        while (n --){
            cin >> a >> b;
            cout << "a:" << a << "  b:" << b << endl;
        }
    }
}

3.不定行m个输入

#include <iostream>
using namespace std;
int main4(){
    int a, b;//定义m个数据
    while(cin >> a >> b){
        cout << "a:" << a << "  b:" << b << endl;
    }
}

4.单行不定数量个输入

#include <iostream>
#include <sstream>
using namespace std;
int main5(){
    string str;
    int a;
    getline(cin, str);
    stringstream ss(str);
    while(ss >> a){
        cout << a << endl;
    }
}

5.不定行不定数量个输入

#include <iostream>
#include <sstream>
using namespace std;
int main6(){
    int a;
    string str;
    while (getline(cin, str)){
        stringstream ss(str);
        while (ss >> a){
            cout << a << endl;
        }
    }
}

6.n行不定数量个输入

#include <iostream>
#include <sstream>
using namespace std;
int main7(){
    int a, n;
    string str;
    cin >> n;
    while(n --){
        getline(cin, str);
        stringstream ss(str);
        while (ss >> a){
            cout << a << endl;
        }
    }
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值