当前位置:网站首页>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;
}边栏推荐
- Precautions for using sneakemake
- YaLM 100B:来自俄罗斯Yandex的1000亿参数开源大模型,允许商业用途
- TP5 Spreadsheet Excle 表格导出
- Yuantou firm offer weekly record 20220627
- Canvas particles: mouse following JS effect
- Introduction to stm32
- Yalm 100b: 100billion parameter open source large model from yandex, Russia, allowing commercial use
- Web development framework - Express (installation and use, static hosting, routing processing, use of Middleware)
- Press key to control LED status reversal
- Flink学习2:应用场景
猜你喜欢

"All majors are persuading them to quit." is it actually the most friendly to college students?

ConstraintLayout(约束布局)开发指南

What if asreml-r does not converge in operation?

Topolvm: kubernetes local persistence scheme based on LVM, capacity aware, dynamically create PV, and easily use local disk

Google began to roll itself, AI architecture pathways was blessed, and 20billion generation models were launched

mmdetection ValueError: need at least one array to concatenate解决方案

How does the brain do arithmetic? Both addition and subtraction methods have special neurons, and the symbol text can activate the same group of cell sub journals

Qingscan use

使用命令行安装达梦数据库

Svg drag dress Kitty Cat
随机推荐
Leetcode 785: judgment bipartite graph
【数组】剑指 Offer II 012. 左右两边子数组的和相等 | 剑指 Offer II 013. 二维子矩阵的和
Oracle/PLSQL: To_ Clob Function
three. JS domino JS special effect
Oracle/PLSQL: Translate Function
pytorch_grad_cam——pytorch下的模型特征(Class Activation Mapping, CAM)可视化库
TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
学习太极创客 — MQTT(九)ESP8266 同时订阅和发布 MQTT 消息
Oracle/PLSQL: NumToYMInterval Function
剑指Offer || :栈与队列(简单)
Getting started with bluecms code auditing
超級詳細,2 萬字詳解,吃透 ES!
Super detailed, 20000 word detailed explanation, thoroughly understand es!
ORM cache package for laravel
对数器
pytorch_ grad_ Cam -- visual Library of class activation mapping (CAM) under pytorch
paddlepaddle 19 动态修改模型的最后一层
Yiwen teaches you Kali information collection
Oracle/PLSQL: From_ Tz function
Oracle/PLSQL: CharToRowid Function
https://github.com/ZouJiu1/PAT