C++ ACM テンプレートの入力

単一入力動作

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
    
    
    /*
    abcdd
    aabbcddd
    */
    string str;
    cin >> str;
    
    return 0;
}

複数のリスト入力操作

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
    
    
    /*
    先给行数,再给出T行
    3
    3 5 7
    6 8 9
    12 9 5
    */
    int T;
    vector<vector<int>> input_data;
    cin >> T;

    while (T--) {
    
    
        int n;
        vector<int> temp;
        cout << "input: ";
        while (cin >> n) {
    
    
            temp.push_back(n);
            if (getchar() == '\n') break;
        }
        
        input_data.push_back(temp);
    }
    
    for (auto temp: input_data) {
    
    
        for (auto n: temp) cout << n << " ";
        cout << endl;
    }
    
    return 0;
}

対応する変更は、マルチリスト操作に基づいて行うことができます。

おすすめ

転載: blog.csdn.net/frighting_ing/article/details/129378264