1024. Palindromic Number (25)

简介: #include #include #include #include #include using namespace std;bool judge(string s){ string st = s; reverse(st.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

bool judge(string s){
    string st = s;
    reverse(st.begin(), st.end());
    if(st == s) return true;
    else return false;
}

void add(string &s){
    string st = s;
    reverse(st.begin(), st.end());
    int c = 0;
    for (int i = (int)st.size() - 1; i >= 0; i--) {
        s[i] = s[i] + st[i] + c - '0';
        if(s[i] > '9'){
            s[i] = s[i] - 10;
            c = 1;
        }else c = 0;
        if((i == 0) && c == 1){
            s = "1" + s;
        }
    }
}

int main(){
    int k;
    string s, st;
    cin >> s >> k;
    if(judge(s)){
        cout << s << 0 << endl;
        return 0;
    }
    for (int i = 1; i <= k; i++) {
        add(s);
        if (judge(s)) {
            cout << s << endl << i << endl;
            return 0;
        }
    }
    cout << s << endl << k << endl;

    return 0;
}

目录
相关文章
|
5天前
|
Python
Number
Number。
11 6
|
1月前
|
JavaScript 前端开发 安全
Number
【10月更文挑战第07天】
46 1
|
5月前
每日一数——梅森数(Mersenne number)
每日一数——梅森数(Mersenne number)
A. Nearly Lucky Number
A. Nearly Lucky Number
56 0
|
人工智能
Constant Palindrome Sum
Constant Palindrome Sum
Nearly Lucky Number
Nearly Lucky Number
117 0
Nearly Lucky Number
成功解决ValueError: Number of passed names did not match number of header fields in the file
成功解决ValueError: Number of passed names did not match number of header fields in the file
成功解决ValueError: Parameter values for parameter (n_estimators) need to be a sequence.
成功解决ValueError: Parameter values for parameter (n_estimators) need to be a sequence.
成功解决ValueError: Parameter values for parameter (n_estimators) need to be a sequence.
1117. Eddington Number(25)
#include #include #include using namespace std; bool cmp(int &a, int &b){ return a > b; } int main() { ...
837 0
|
文件存储
1019. General Palindromic Number (20)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number.
908 0