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

整型存储

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;
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-18 16:32
quench@0916:一顿操作猛如虎,一看工资2500
点赞 评论 收藏
分享
05-05 21:45
已编辑
广州大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务