2 条题解
-
3
点个赞吧
#include <iostream> #include <string> using namespace std; string removeKDigits(string num, int k) { string result; for (char digit : num) { while (!result.empty() && k > 0 && digit < result.back()) { result.pop_back(); k--; } result.push_back(digit); } // 如果还有剩余的k需要删除,则从末尾删除 while (k > 0 && !result.empty()) { result.pop_back(); k--; } // 去除前导零 size_t nonZeroIndex = 0; while (nonZeroIndex < result.size() && result[nonZeroIndex] == '0') { nonZeroIndex++; } result = result.substr(nonZeroIndex); // 如果结果为空,返回0 return result.empty() ? "0" : result; } int main() { string n; int s; cin >> n >> s; cout << removeKDigits(n, s) << endl; return 0; } -
0
#include<bits/stdc++.h> using namespace std; string st; int n,len,p; int main() { freopen("delete.in","r",stdin); freopen("delete.out","w",stdout); cin>>st; len=st.length(); cin>>n; for (int i=1;i<=n;i++) { p=0; for (int j=1;j<=len-1;j++) if (st[j-1]>st[j]) { st.erase(j-1,1); len--; p=1; break; } if (!p) { st.erase(len-1,1); len--; } } while (st[0]'0') st.erase(0,1); if (st"") cout<<0; else cout<<st; return 0; }
- 1
信息
- ID
- 65
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- (无)
- 递交数
- 149
- 已通过
- 63
- 上传者