求每一位数和

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

猜你喜欢

转载自www.cnblogs.com/zhanghua-322/p/11302390.html
今日推荐