直接模拟 如果后一位比前一位小,那就一直 向前 pop()掉 维护他单调递增;

1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #include<stdio.h> 6 #include<vector> 7 using namespace std; 8 9 char str[1123]; int res[1123],num; 10 int main( ) 11 { 12 while( scanf("%s%d",&str,&num) != EOF ) 13 { 14 int len = strlen( str ); int k = 0; 15 for( int i = 0; i < len; i++ ) 16 if( k != 0 && num != 0 && (str[i] - '0') < res[k] ) 17 { 18 while( k != 0 && num != 0 && (str[i] - '0') < res[k] ){ 19 k--; num--; 20 } 21 res[++k] = ( str[i] - '0' ); 22 }else res[++k] = ( str[i] - '0' ); 23 while( num-- && k != 0 )k--; 24 bool fell = false; bool fall = false; 25 for( int i = 1; i <= k; i++ ) 26 if( res[i] == 0 ){ if( fell )cout<<res[i]; } 27 else { fell = true; cout<<res[i]; } 28 if( !fell ) cout<<0;puts(""); 29 } 30 return 0; 31 }