PAT A1019 General Palindromic Number (20 分)

AC代码

#include <cstdio>
const int max_n = 1000;
long long ans[max_n];
int num = 0;
void change(long long a, long long d) {
    do {
        ans[num++] = a % d;
        a /= d;
    } while(a != 0);
}

int main() {
    #ifdef ONLINE_JUDGE
    #else
        freopen("1.txt", "r", stdin);
    #endif // ONLINE_JUDGE}
    long long a, d;
    scanf("%lld %lld", &a, &d);
    change(a, d);
    bool flag = 1;
    for(int i = 0; i < num - 1- i; i++) {
        if(ans[i] != ans[num - 1 - i]) flag = false;
    }
    if(flag == true) printf("Yes\n");
    else if(flag == false) printf("No\n");
    for(int i = num - 1; i >= 0; i--) {
        if(i != num - 1) printf(" ");
        printf("%d", ans[i]);
    }
    return 0;
}
posted @ 2019-08-04 23:46  哨音  阅读(137)  评论(0编辑  收藏  举报