当前位置:网站首页>PAT甲级 1024 Palindromic Number
PAT甲级 1024 Palindromic Number
2022-06-27 02:44:00 【九是否非随机的称呼】
数值可能越界long long,要用string保存并计算的
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
string add(string &s, string &s0){
string st;
int x, y, z, tmp, h = 0;
reverse(s.begin(), s.end());
reverse(s0.begin(), s0.end());
for(int i=0; i<s.length(); i++){
x = s[i] - '0';
y = s0[i] - '0';
z = (x + y + h)/10;
tmp = (x + y + h)%10;
h = z;
st += to_string(tmp);
if(i==(s.length() - 1) && z > 0) st += to_string(z);
}
reverse(st.begin(), st.end());
return st;
}
int main(void){
string s, s0, sk;
long long a, c, f, i, j, k;
cin>>s>>k;
for(i=0; i<k; i++){
s0 = s;
reverse(s0.begin(), s0.end());
if(s0==s) break;
s = add(s, s0);
}
cout<<s<<endl;
cout<<i;
return 0;
}边栏推荐
- Fork (), exec (), waitpid (), $? > > in Perl 8 combination
- Laravel 的 ORM 缓存包
- Uninstallation of Dameng database
- [Shangshui Shuo series] day 6
- Enterprise digital transformation: informatization and digitalization
- Record the method of reading excel provided by unity and the solution to some pits encountered
- STM32入门介绍
- Qingscan use
- Hot discussion: what are you doing for a meaningless job with a monthly salary of 18000?
- Paddlepaddle 20 implementation and use of exponentialmovingaverage (EMA) (support static graph and dynamic graph)
猜你喜欢

事业观、金钱观与幸福观

Enterprise digital transformation: informatization and digitalization

Why pass SPIF_ Sendchange flag systemparametersinfo will hang?

一文教你Kali信息收集

lottie.js创意开关按钮动物头像

Installing the Damon database using the command line

Canvas particles: mouse following JS effect

【微服务|Sentinel】降级规则|慢调用比例|异常比例|异常数

three.js多米诺骨牌js特效

Press key to control LED status reversal
随机推荐
TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
I earned 3W yuan a month from my sideline: the industry you despise really makes money!
Summer planning for the long river
Flink学习2:应用场景
Oracle/PLSQL: NumToYMInterval Function
Learning Tai Chi Maker - mqtt (VII) advanced mqtt theme
Installing the Damon database using the command line
Leetcode 785: judgment bipartite graph
Precautions for using sneakemake
"All majors are persuading them to quit." is it actually the most friendly to college students?
TP5 spreadsheet excel table export
Solve the problem of error reporting in cherry pick submission
超级详细,2 万字详解,吃透 ES!
剑指Offer || :栈与队列(简单)
使用命令行安装达梦数据库
The use and introduction of pytorch 23 hook and the implementation of plug and play dropblock based on hook
Oracle/PLSQL: CharToRowid Function
Flink learning 3: data processing mode (stream batch)
Dameng database installation
Mmdetection uses yolox to train its own coco data set
https://github.com/ZouJiu1/PAT