题解 | #数字颠倒#

数字颠倒

http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe

本题没有啥难度,对数字进行处理,即可。

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


int main () {
    int N;
    cin >> N;
    vector<int> res;
    if (N < 10) {
        cout << N;
    } else {
          while (1) {
            int temp = N / 10;
            int num = N - temp * 10;
            N /= 10;
            res.push_back(num);
            if (temp < 10) {
                // 表示取到了最后一个数字
                res.push_back(temp);
                break;
            }
        }  
    }
    
    for (vector<int>::iterator iter = res.begin(); iter != res.end(); iter++) {
        cout << *iter;
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
勇敢牛牛不怕困难,希望能过初筛
投递韶音科技等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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