PAT甲级题解 1019

一道水题 进制转换模拟即可

#include<bits./stdc++.h>
using namespace std;

const int MAXN = 100010;
int main(void)
{
    freopen("pat0314/in.txt","r",stdin);
    int n,radix;
    cin>>n>>radix;
    if(n == 0)
    {
        cout<<"Yes"<<endl;
        cout<<0<<endl;
        return 0;
    }
    int num = 0;
    int z[MAXN];
    while(n != 0)
    {
        z[num++] = n % radix;
        n /= radix;
    }
    string s;
    string reversestr;
    for(int i = 0;i<num;i++)
    {
        string temp;
        s += to_string(z[i]);
        reversestr = to_string(z[i]) + reversestr; 
    }
    // cout<<s<<endl;
    // cout<<reversestr<<endl;
    if(reversestr == s)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    for(int i = num - 1;i>=0;i--)
    {
        if(i == num - 1)
        {
            printf("%d",z[i]);
        }
        else
        {
            printf(" %d",z[i]);
        }
    }
    return 0;
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页