回文数(牛客最小回文数去除前导0)***

回文数

#include<iostream>
using namespace std;

signed main(){
    string a, b;
    for(int i = 0; i < 10; ++i){
        int n; cin >> n;
        if(n & 1) b += ('0' + i);
        for(int j = 0; j < n / 2; ++j) a += ('0' + i);
    }
    if(b.size() > 1) cout << -1 << endl;
    else{
        int index = 0;
        while(index < a.size() && a[index] == '0') ++index;
        if(index == a.size() && index) cout << -1 << endl;
        else{
            swap(a[0], a[index]);
            cout << a << b;
            for(int i = a.size() - 1; i >= 0; --i) cout << a[i];
        }
    }
    
    return 0;
}
posted @ 2025-03-19 19:49  awei040519  阅读(3)  评论(0)    收藏  举报