80分,求调!全AC必关!!!
查看原帖
80分,求调!全AC必关!!!
1731656
lyx20131111楼主2025/7/23 22:25

全AC必关!

#include <bits/stdc++.h>

using namespace std;

int main() {
    int k;
    long long x;
    cin >> k >> x;
    if (x == 0) {
        cout << "1";
        for (int i = 0; i < k; i++) cout << "0";
        cout << endl;
        return 0;
    }
    string x_str = to_string(x);
    int x_len = x_str.length();
    if (k + 1 > x_len) {
        cout << "1";
        int zeros = k - x_len;
        for (int i = 0; i < zeros; i++) cout << "0";
        cout << x_str << endl;
    } 
    else {
        string result = x_str;
        int carry = 1;
        int i = x_str.length() - 1;
        while (carry > 0 && i >= 0) {
            int sum = (x_str[i] - '0') + carry;
            result[i] = (sum % 10) + '0';
            carry = sum / 10;
            i--;
        }
        if (carry > 0) {
            result = "1" + result;
        }
        
        cout << result << endl;
    }
    
    return 0;
}
2025/7/23 22:25
加载中...