1136 A Delayed Palindrome (20 分)难度: 简单 / 知识点: 模拟
Posted 辉小歌
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1136 A Delayed Palindrome (20 分)难度: 简单 / 知识点: 模拟相关的知识,希望对你有一定的参考价值。
https://pintia.cn/problem-sets/994805342720868352/problems/994805345732378624
#include<bits/stdc++.h>
using namespace std;
vector<int>a,b,c;
bool check(vector<int> s)
vector<int> temp=s;
reverse(temp.begin(),temp.end());
return s==temp;
vector<int> add(vector<int> A,vector<int> B)
vector<int>C;
int t=0;
for(int i=0;i<A.size()||i<B.size();i++)
if(i<A.size()) t+=A[i];
if(i<B.size()) t+=B[i];
C.push_back(t%10);
t/=10;
if(t) C.push_back(1);
return C;
void print(vector<int>A)
for(int i=A.size()-1;i>=0;i--) cout<<A[i];
int main(void)
string s; cin>>s;
for(int i=s.size()-1;i>=0;i--) a.push_back(s[i]-'0');
if(check(a))
printf("%s is a palindromic number.",s.c_str());
return 0;
for(int i=1;i<=10;i++)
b=a; reverse(b.begin(),b.end());
c=add(a,b);
if(!check(c)) print(a),cout<<" + ",print(b),cout<<" = ",print(c),cout<<"\\n";
else
print(a),cout<<" + ",print(b),cout<<" = ",print(c),cout<<"\\n";
print(c),cout<<" is a palindromic number.";
return 0;
a=c;
puts("Not found in 10 iterations.");
以上是关于1136 A Delayed Palindrome (20 分)难度: 简单 / 知识点: 模拟的主要内容,如果未能解决你的问题,请参考以下文章
pat 1136 A Delayed Palindrome(20 分)
PAT 1136 A Delayed Palindrome[简单]