题解 | #整型存储# 按要求定义了一个类

整型存储

https://www.nowcoder.com/practice/5391e3118a5f419d8198264c5a8c805a

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

class solution{
public:
    vector<pair<int,int>>ints;
    bool input(int x){
        if(ints.size()==10) return true;
        string y=to_string(x);
        reverse(y.begin(),y.end());
        int x_reverse=stoi(y);
        ints.push_back({x,x_reverse});
        return false;
    }

    void print(){
        for(pair it:ints){
            cout<<it.first<<" "<<it.second<<endl;
        }
    }
};

int main() {
    int x;
    solution Solution;
    while(cin>>x){
        if(!x || Solution.input(x)){
            Solution.print();
            break;
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务