031 山寨版istream_iterator

#include <iostream>
#include <string>

using namespace std;
template <class T>
class CMyistream_iterator
{

    // 在此处补充你的代码
public:
    T a;

    CMyistream_iterator(istream& cin){
        cin >> a;
    }

    operator T *() {
        return &a;
    }

      CMyistream_iterator & operator++(int ab) { //右侧++需要传无用int 类型参数
        cin >> a;
        return * this;
    }

};



int main()
{
    int t;
    cin >> t;
    while (t--) {
        CMyistream_iterator<int> inputInt(cin);
        int n1, n2, n3;
        n1 = *inputInt; //读入 n1
        int tmp = *inputInt;
        cout << tmp << endl;
        inputInt++;
        n2 = *inputInt; //读入 n2
        inputInt++;
        n3 = *inputInt; //读入 n3
        cout << n1 << " " << n2 << " " << n3 << " ";
        CMyistream_iterator<string> inputStr(cin);
        string s1, s2;
        s1 = *inputStr;
        inputStr++;
        s2 = *inputStr;
        cout << s1 << " " << s2 << endl;
    }
    return 0;
}

上一篇:Codeforces Round #773 -B&C


下一篇:【蓝桥杯】试题 算法训练 字符串编辑