当前位置:网站首页>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;
}边栏推荐
- 流沙画模拟器源码
- How do I simplify the development of interfaces in open source systems?
- Oracle/PLSQL: Translate Function
- 学习太极创客 — MQTT 第二章(三)保留消息
- Mmdetection valueerror: need at least one array to concatenate solution
- Precautions for using sneakemake
- Flink学习5:工作原理
- "All majors are persuading them to quit." is it actually the most friendly to college students?
- paddlepaddle 20 指数移动平均(ExponentialMovingAverage,EMA)的实现与使用(支持静态图与动态图)
- Quicksand painting simulator source code
猜你喜欢

【一起上水硕系列】Day 6

【数组】剑指 Offer II 012. 左右两边子数组的和相等 | 剑指 Offer II 013. 二维子矩阵的和

Calculation of average wind direction and speed (unit vector method)

学习太极创客 — MQTT(九)ESP8266 同时订阅和发布 MQTT 消息

Learn Tai Chi Maker - mqtt Chapter 2 (3) reserved messages

Learning Tai Chi Maker - mqtt (VII) advanced mqtt theme

Flink学习3:数据处理模式(流批处理)

DAMA、DCMM等数据管理框架各个能力域的划分是否合理?有内在逻辑吗?

What if asreml-r does not converge in operation?

Mmdetection uses yolox to train its own coco data set
随机推荐
Oracle/PLSQL: Translate Function
Getting started with Scala_ Immutable list and variable list
JWT certification process and use cases
ORM cache package for laravel
Paddlepaddle 20 implementation and use of exponentialmovingaverage (EMA) (support static graph and dynamic graph)
QIngScan使用
流沙画模拟器源码
正则表达式:语法
pytorch_grad_cam——pytorch下的模型特征(Class Activation Mapping, CAM)可视化库
2022茶艺师(高级)上岗证题库模拟考试平台操作
Parameter estimation -- Chapter 7 study report of probability theory and mathematical statistics (point estimation)
Flink学习2:应用场景
dat. gui. JS star circle track animation JS special effect
Flink learning 3: data processing mode (stream batch)
C language -- Design of employee information management system
剑指Offer || :栈与队列(简单)
YaLM 100B:来自俄罗斯Yandex的1000亿参数开源大模型,允许商业用途
Flink学习1:简介
Detailed explanation of ThreadLocal
学习太极创客 — MQTT 第二章(二)ESP8266 QoS 应用
https://github.com/ZouJiu1/PAT