当前位置:网站首页>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 does the C # TCP server limit the number of connections to the same IP?
- Yiwen teaches you Kali information collection
- Flink学习1:简介
- Detailed explanation of ThreadLocal
- Flink Learning 2: Application Scenarios
- 超級詳細,2 萬字詳解,吃透 ES!
- Super détaillé, 20 000 caractères détaillés, mangez à travers es!
- 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
- 清华&华为等 综述 | 语义通信:原则与挑战
猜你喜欢

Flink learning 1: Introduction

元透实盘周记20220627

I earned 3W yuan a month from my sideline: the industry you despise really makes money!

three. JS domino JS special effect

Dameng database installation

Flink學習2:應用場景

docker部署redis集群

学习太极创客 — MQTT(六)ESP8266 发布 MQTT 消息

pytorch 22 8种Dropout方法的简介 及 基于Dropout用4行代码快速实现DropBlock

一文教你Kali信息收集
随机推荐
pytorch 22 8种Dropout方法的简介 及 基于Dropout用4行代码快速实现DropBlock
Summer planning for the long river
Yuantou firm offer weekly record 20220627
Learn Tai Chi Maker - mqtt (VI) esp8266 releases mqtt message
Learn Tai Chi Maker - mqtt (VIII) esp8266 subscribe to mqtt topic
QIngScan使用
Introduction to stm32
svg拖拽装扮Kitty猫
ORM cache package for laravel
Paddlepaddle 21 is implemented based on dropout with 4 lines of code droplock
TP5 Spreadsheet Excle 表格导出
I earned 3W yuan a month from my sideline: the industry you despise really makes money!
2022中式面点师(高级)复训题库及在线模拟考试
Dameng database installation
TP5 spreadsheet excel table export
pytorch_ grad_ Cam -- visual Library of class activation mapping (CAM) under pytorch
Learn from Taiji Maker - mqtt Chapter 2 (I) QoS service quality level
Laravel 的 ORM 缓存包
Why pass SPIF_ Sendchange flag systemparametersinfo will hang?
使用命令行安装达梦数据库
https://github.com/ZouJiu1/PAT