关闭

PAT 1019. General Palindromic Number (20)

标签: PAT
194人阅读 评论(0) 收藏 举报
分类:

n变为b进制后 其原来的顺序和从后往前排是否相等 即倒置后是否一样

只想说PAT上的测试数据b有点小(应该是故意的 毕竟只有20分)

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int main()
{
    int n,b;
    int a[10001];
    scanf("%d%d",&n,&b);
    int s=n;
    int i,j;
    i=0;
    if(s==0)
        a[i++]=0;
    else
    while(s!=0)
    {
        a[i++]=s%b;
        s/=b;
    }
    int m=i;
    j=i-1;
    i=0;
    while(a[i]==a[j]&&i!=j)
    {
        i++;
        j--;
    }
    if(i!=j)
        printf("No\n");
    else
        printf("Yes\n");
        printf("%d",a[m-1]);
    for(j=m-2;j>=0;j--)
        printf(" %d",a[j]);
        printf("\n");
    return 0;
}


0
0
查看评论

浙大 PAT 1019. General Palindromic Number (20)

1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 ...
  • IAccepted
  • IAccepted
  • 2014-03-04 14:44
  • 1590

浙大 PAT Advanced level 1019. General Palindromic Number (20)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number...
  • fanxingzju
  • fanxingzju
  • 2016-05-13 18:04
  • 154

PAT 甲级1019. General Palindromic Number (20)

题目:点击打开链接 思路:简单的进制转换,考虑单个数字情况。 代码: #include #include #include using namespace std; int main() { long long N; int b; cin>>N>>b; vec...
  • changeforeve
  • changeforeve
  • 2017-08-13 15:24
  • 52

【PAT甲级】1019. General Palindromic Number (20)

注:特殊情况 n == 0.#include <stdio.h>int main(int argc, char *argv[]) { int n, b; scanf("%d %d", &n, &b); if (n == 0) {...
  • lambsnow
  • lambsnow
  • 2016-10-14 13:33
  • 113

[PAT]1019. General Palindromic Number (20)@Java

1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 ...
  • zjkC050818
  • zjkC050818
  • 2017-10-16 20:10
  • 79

PAT 1019. General Palindromic Number (20)

1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 ...
  • u010069101
  • u010069101
  • 2014-02-26 20:06
  • 403

PAT甲级.1019. General Palindromic Number (20)

1019. General Palindromic Number (20) 题目: A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. ...
  • R11happy
  • R11happy
  • 2016-08-20 11:04
  • 124

PAT甲级1019. General Palindromic Number (20)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number...
  • liaotl10
  • liaotl10
  • 2017-02-27 00:25
  • 73

【PAT】1019. General Palindromic Number (20)

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1019 简单题。将十进制数a转换成以b为奇数的数,判断转换后的数是否是符合回文串的特点。 A number that will be the same when it is written f...
  • realxuejin
  • realxuejin
  • 2013-08-21 16:15
  • 1013

PAT (Advanced) 1019. General Palindromic Number (20)

原题:1019. General Palindromic Number (20) 解题思路: 1.将给定的数按给定基数分解存入数组 2.判定数组是否对称 C++代码如下: #include #include int num[200]; int cnt;//保...
  • cx86918626
  • cx86918626
  • 2017-09-23 22:56
  • 37
    个人资料
    • 访问:17942次
    • 积分:752
    • 等级:
    • 排名:千里之外
    • 原创:56篇
    • 转载:11篇
    • 译文:0篇
    • 评论:5条
    最新评论