1019 General Palindromic Number (20分)甲级真题

PAT甲级真题 1019 General Palindromic Number (20分) C++实现(注意测试点2、4) 题目 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. All single digit numbers are palindromic num... 阅读详情

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. All single digit numbers are palindromic numbers.

Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N>0 in base b≥2, where it is written in standard notation with k+1 digits a​i​​ as ∑​i=0​k​​(a​i​​b​i​​). Here, as usual, 0≤a​i​​<b for all i and a​k​​ is non-zero. Then N is palindromic if and only if a​i​​=a​k−i​​ for all i. Zero is written 0 in any base and is also palindromic by definition.

Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.

Input Specification:

Each input file contains one test case. Each case consists of two positive numbers N and b, where 0<N≤10​9​​ is the decimal number and 2≤b≤10​9​​ is the base. The numbers are separated by a space.

Output Specification:

For each test case, first print in one line Yes if N is a palindromic number in base b, or No if not. Then in the next line, print N as the number in base b in the form "a​k​​ a​k−1​​ ... a​0​​". Notice that there must be no extra space at the end of output.

Sample Input 1:

27 2

Sample Output 1:

Yes
1 1 0 1 1

Sample Input 2:

121 5

Sample Output 2:

No
4 4 1

题目大意:判断输入N的d进制数是否是回文数,是就输出Yes,否则输出No,第二行输出N经过d进制转换的数

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n, d, flag = 0;
    vector<int> v;
    cin >> n >> d;
    while (n) {
        v.push_back(n % d);
        n /= d;
    }
    for (int i = 0; true; i++) {
        if (i >= v.size() - i - 1) break;
        if (v[i] != v[v.size() - i - 1]) flag = 1;
    }
    if (flag) cout << "No\n";
    else cout << "Yes\n";
    for (int i = 0; i < v.size(); i++) {
        if (i != 0) cout << " ";
        cout << v[v.size() - i - 1];
    }
    return 0;
}

 

雷电模拟器+Auto.js避坑指南:用桥接模式解决PC与模拟器连接超时问题 本文详细解析了雷电模拟器与Auto.js联调中的桥接模式应用,解决PC与模拟器连接超时问题。通过桥接模式配置、高频故障排查及多开环境下的高阶配置,提升开发效率与稳定性,特别适合需要稳定网络连接的Auto.js开发者。 阅读详情

相关推荐

ADB命令解锁Android手机屏幕的3种实用方法(附详细步骤)

本文详细介绍了在Android手机屏幕失灵或密码遗忘时,利用ADB命令解锁屏幕的三种实用方法。包括通过ADB模拟输入事件、移除锁屏认证文件(需Root权限)以及结合恢复模式抢救数据。文章提供了详细的操作步骤与风险提示,强调提前开启USB调试的重要性,是Android用户应对紧急锁屏情况的有效技术指南。

weixin_29229055的博客 918

【PAT(甲级)】1019 General Palindromic Number

【PAT(甲级)】1019 General Palindromic Number 用迭代器进行简单的写法更方便

weixin_55202895的博客 247

离线安装vue脚手架,内网安装@vue/cli

公司开发环境使用内网,无法用外网,搭建环境的时候,发现内网系统没有安装vue脚手架,我搜了很多文章,发现他们的方法对我都不适用,然后就自己摸索,最终皇天不负有心人,终于被我安装上了,一下是我内网离线安装vue/cli的方法,希望能帮助到有需要的小伙伴! 因为npm被集成在nodejs中,而安装nodejs只需要把nodejs安装包copy到内网电脑安装就行,比较简单,这里就不多做演示。 在外网电脑上,使用npm install -g xxxx命令下载好我们所需要的各个安装包,比如: npm insta

Liberty_yes的博客 1万+

1019. General Palindromic Number (20)-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. All s

柳婼 の blog 1855

【Blockly开发教程】01 初识Blockly

Blockly 是由 Google 开发的开源代码库,它可以为网页程序和移动端应用程序添加可视化代码编辑器。

Bright的博客 4512

手把手教你用DaVinci Configurator配置AUTOSAR SWC接口(含RTE避坑指南)

本文提供了一份基于DaVinci Configurator工具的AUTOSAR软件组件(SWC)接口配置实战指南。文章详细拆解了SR(发送者-接收者)和CS(客户端-服务器)接口的配置流程,并重点分享了运行时环境(RTE)生成阶段在多核部署、数据类型匹配等常见陷阱中的避坑方案与调试技巧,旨在帮助汽车电子工程师高效完成配置并规避错误。

uuu88的博客 547

1019 General Palindromic Number (20 分)(C语言实现)(PAT)

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. All single digit numbers are palindromic numbers...

JJJ's blog 254

PyTorch生成式人工智能(1)——神经网络与模型训练过程详解

在本节中,我们介绍了传统机器学习与人工神经网络间的差异,并了解了如何在实现前向传播之前连接网络的各个层,以计算与网络当前权重对应的损失值;实现了反向传播以优化权重达到最小化损失值的目标。并实现了网络的所有关键组成——前向传播、激活函数、损失函数、链式法则和梯度下降,从零开始构建并训练了一个简单的神经网络。

盼小辉丶的博客 1万+

[PAT A1019]General Palindromic Number

[PAT A1019]General Palindromic Number 题目描述 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, ...

欢迎来到我的编程小屋 678

基于Pascal VOC数据集的YOLOv8目标检测系统实现:人、鸟、猫、牛、电视、车等20类目标识别与UI界面部署全流程详解

VOC 2007、VOC 2012 两个主要版本;每个图像提供 bounding box(目标框)+ 目标类别;共计 20 类,所有图像手工标注,质量高。完整复现 Pascal VOC 20类检测任务成功训练 YOLOv8 模型实现可视化 UI + 实时检测系统支持多平台部署和演示。

YOLO 771

基于Spring Security 6的OAuth2 系列之二 - 客户端--非代码演示授权码模式

至此,我们就使用浏览器+postman工具演示了通过授权码模式去获取Gitee的用户信息。这过程中,我们只是遵循OAuth2的流程,就能够实现授权方法。那么接下来,我们采用代码方式来实现这个流程。

代码让AI扣 1813

pat 甲级1019 General Palindromic Number

题意:给两数,前面那个是十进制数(dicimal system),后面那个是要转换的进制数,回文数就是正着写(written forwards ),反正写(written backwards)都是相同的,如123321,题目是要判断转进制以后是不是回文数; 思路:用除基取余法转换进制存在数组里面,for判断头尾数是不是相等,不等就输出no跳出循环,等的话就往下输出yes,数组倒着输就是转进制数; 代码: #include<cstdio> #include<iostream&gt..

m0_51711089的博客 797

【Unity-UGUI控件全面解析】| Layout自动布局组件详解

UGUI中有个自动布局组件Auto Layout,主要包含下面几个模块(点击可进入官方文档下查看描述): 自动布局 布局元素 (Layout Element) 水平布局组 (Horizontal Layout Group) 垂直布局组 (Vertical Layout Group) 网格布局组 (Grid Layout Group) 内容大小适配器 (Content Size Fitter) 自动布局系统 基于布局元素和布局控制器的概念。一个布局元素是具有矩形变换以及其他可选组件的游戏对象。布局元素对自身

努力前行,总会成为自己心中的那道光 2万+

1019 General Palindromic Number (20分)-PAT甲级真题

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. All single digit numbers are palindromic numbers...

Samson的博客 166

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

PAT甲级 1019 General Palindromic Number

PAT甲级 1019 General Palindromic Number 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. All single...

旺崽的博客 2867

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

PAT甲级1019 General Palindromic Number

PAT 甲级 1019 General Palindromic Number 题目概述:给一个10进制正整数N,和一个base(进制),用base进制来表示这个10进制的数,比如27 2,将27用2进制表示为11011,而11011是回文数,就输出Yes,然后打印1 1 0 1 1,反之输出No,然后打印这几个数 package higherlevel; import java.util.Arr...

优快云_Lrcx的博客 250

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Day52: [PAT甲级] 1019 General Palindromic Number (20分)

Day52: [PAT甲级] 1019 General Palindromic Number (20分) 题源: 来自PAT真题库: https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 代码: dirty code凑合看吧 #include<iostream> #include&l...

qq2215459786的博客 237

PAT甲级 - 1019 General Palindromic Number (20 分)

题目链接: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 num...

158

PAT 甲级 1019(General Palindromic Number)

PAT 甲级 1019题目要求翻译代码思路 题目要求 翻译 判断转换进制后的数是不是回文 代码 #include<iostream> #include<vector> using namespace std; vector<int> v; bool transfor(int n,int b) { v.clear(); do{ v.push_back(n%b); n /=b; }while(n!=0);//“除基取余

qq_42865772的博客 238

PAT甲级 1019 General Palindromic Number (20分)

1019 General Palindromic Number (20分) 题目链接:PAT A 1019 题目大意:一个数如果正着读反着读结果都一样,那么这个数就被称为回文数。现在给出一个十进制数n和一个进制b,要求判断n在b进制下是不是回文数。 思路分析:这题很简单,直接求出b进制下的数并转换为字符串,然后调用reverse函数反转与之比较,如果相同就是回文数,否则不是。 坑点:一开始直接...

weixin_43684054的博客 235

1019 General Palindromic Number (20)(20 分)

1 题目 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. All single digit numbers are palindromic n...

大山喵写博客的地方 626

【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 aPalindromic Number. For example, 1234321 is a palindromic number. All sing...

CrystalXueNing的博客 237

1019 General Palindromic Number (20分)

1019 General Palindromic Number (20分) PAT甲级链接 结尾不能有空格,熟悉回文怎么判断就很简单了 #include<iostream> using namespace std; int n,d; int a[100]; int main() { cin>>n>>d; int ans=0; while(n){ a[ans]=n%d; n=n/d; ans++; } int flag=0; for(int i=0;

南京师范大学中北学院 170

PAT 甲级 1019  General Palindromic Number

1019 General Palindromic Number (20 point(s)) 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. A...

漫浸天空的雨色的备忘录~ 794

【PAT甲级题解记录】1019 General Palindromic Number (20 分)

问题描述 给定一个正整数N,求其作为b进制数时是否为回文数。 解题思路 进制转化完后存储下来,半个循环对比左右数值即可。

retr0的博客 392

【PAT甲级 BigInteger】1019 General Palindromic Number (20 分) Java版 7/7通过

题目 这题用Java的BigInteger做,可以操作任意长度的数字,感觉有一点取巧了。 如果C或者C++的话,应该还需要手动处理一下这个20位长度的大数输入。 思路就是: 输入一个数,把这个数乘以二,将结果与原来的数字比较 如果发现只是数字顺序上的改变,则输出Yes,否则输出No 最后把乘以二的结果输出一下 代码 import java.math.BigInteger; import ja...

寒泉 1万+
上一篇: 1015 Reversible Primes (20分) 甲级真题
下一篇: 1035 Password (20分)甲级真题
阳青
博客等级 码龄7年 51粉丝 61原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值