Algo-Trian
This commit is contained in:
39
Algorithm/Greedy/P1106 删数问题.cpp
Normal file
39
Algorithm/Greedy/P1106 删数问题.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <deque>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
string s;
|
||||
int k;
|
||||
cin >> s >> k;
|
||||
deque<char> q;
|
||||
|
||||
for(char curr : s) {
|
||||
while(!q.empty() && k > 0 && q.back() > curr){
|
||||
q.pop_back();
|
||||
k--;
|
||||
}
|
||||
q.push_back(curr);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3> k <20><><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD>ɾ<EFBFBD><C9BE>ջβ
|
||||
while(k > 0 && !q.empty()) {
|
||||
q.pop_back();
|
||||
k--;
|
||||
}
|
||||
|
||||
// ƴ<>ӽ<EFBFBD><D3BD><EFBFBD>
|
||||
string res;
|
||||
for(char c : q) res += c;
|
||||
|
||||
// ȥ<><C8A5>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
||||
int i = 0;
|
||||
while(i < res.size() && res[i] == '0') i++;
|
||||
res = res.substr(i);
|
||||
if(res.empty()) res = "0";
|
||||
|
||||
cout << res << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user