/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 320.0 KiB

Code

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

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("in.txt", "r", stdin);
    #endif

    int tc, n, k;

    cin >> tc;
    while(tc--) {
        cin >> n >> k;
        
        string s;
        cin >> s;

        if(k == n) {
            cout << "0" << endl;
            continue;
        }

        for(int d = 0; k and (d < 10); ) {
            bool found = false;
            char c = '0' + d;
            for(int i = n-1; i >= 0; i--) {
                if(s[i] == c) {
                    s[i] = '-';
                    found = true;
                    k--;
                    break;
                }
            }
            if(!found) {
                d++;
            }
        }

        for(int i = 0; i < n; i++) {
            if(s[i] != '-') {
                cout << s[i];
            }
        }
        cout << 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 05:51:57
Judged At
2024-11-11 02:22:51
Judged By
Score
0
Total Time
2ms
Peak Memory
320.0 KiB