TZOJ 4493: Remove Digits
4493: Remove Digits ![分享至QQ空间](http://www.tzcoder.cn/acmhome/forum/images/ico_qzone.gif)
时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte
总提交: 329 测试通过:77
View Code
总提交: 329 测试通过:77
描述
Given an N-digit number, you should remove K digits and make the new integer as large as possible.
输入
The first line has two integers N and K (1 ≤ K<N≤500000).
The next line has a N-digit number with no leading zero.
输出
Output the largest possible integers by removing K digits.
样例输入
样例输出
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <bits/stdc++.h> 2 using namespace std; 3 char s[500005]; 4 int main() 5 { 6 ios::sync_with_stdio(false); 7 int n,k,num=0; 8 char c; 9 s[0]='9'; 10 cin>>n>>k; 11 for(int i=0;i<n;i++){ 12 cin>>c; 13 while(c>s[num]){ 14 if(!k||!num) break; 15 num--,k--; 16 } 17 s[++num]=c; 18 } 19 if(k) 20 num=num-k; 21 s[++num]='\0'; 22 cout << s+1 << endl; 23 return 0; 24 }