/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error 3ms 584.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 = 0; i < n; 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-10-29 17:27:58
Judged At
2024-11-11 02:35:46
Judged By
Score
0
Total Time
3ms
Peak Memory
584.0 KiB