码迷,mamicode.com
首页 > 其他好文 > 详细

求每一位数和

时间:2019-08-05 13:39:12      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:clu   bsp   col   ret   stack   std   turn   code   top   

#include <iostream>
#include <stack>
using namespace std;
int main()
{
    int r,n,ans=0;
    stack<int>s;
    cin>>n>>r;
    while(n)
    {
        s.push(n%r);
        n/=r;
    }
    while(!s.empty())
    {
        ans+=s.top();
        s.pop();
    }
    cout<<ans<<endl;
    return 0;
}

 

求每一位数和

标签:clu   bsp   col   ret   stack   std   turn   code   top   

原文地址:https://www.cnblogs.com/zhanghua-322/p/11302390.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!