/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;


string shorten(string s)
{
    for(int i = 0; i < s.size() - 1; i++) {
        if(s[i] < s[i + 1]) {
            return s.substr(0, i) + s.substr(i + 1);
        }
    }
    return s.substr(0, s.size() - 1);
}


string solve(string s, int n, int k)
{
    if(k == n) {
        return "0";
    }

    if(k == 0) {
        return s;
    }

    while(k--) {
        s = shorten(s);
    }

    if(s[0] == '0') {
        return "0";
    }
    return s;
}

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("input1.txt", "r", stdin);
        //freopen("myout.txt", "w", stdout);
    #endif

    int tc, n, k;
    string s;

    cin >> tc;
    while(tc--) {
        cin >> n >> k >> s;
        cout << solve(s, n, k) << endl;
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1006 Remove K Digits
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-08 08:51:26
Judged At
2024-11-11 02:22:49
Judged By
Score
100
Total Time
2ms
Peak Memory
320.0 KiB