1019 General Palindromic Number

2019-08-01  本文已影响0人  79d12e22ec53
#include <cstdio>
#include <cstring>

bool judge(int num[], int len) {
    for(int i=0; i<=len/2; i++) {
        if(num[i] != num[len-1-i]) return false;
    }
    return true;
}

int main(int argc, char *argv[]) {
    int N, b;
    int num[40];
    scanf("%d %d", &N, &b);
    
    int len=0;
    do{
        num[len++] = N%b;
        N = N/b;
    }while(N != 0);
    
    bool flag = judge(num, len);
    if(flag == true) printf("Yes\n");
    else printf("No\n");
    printf("%d", num[len-1]);
    for(int i=len-1-1; i>=0; i--) {
        printf(" %d", num[i]);
    }
    
    return 0;
}

上一篇下一篇

猜你喜欢

热点阅读