标签:blog io ar os sp for 2014 log amp
///给你一数字,删除其中的m位使其最小 ///贪心:前面的数要小于后面的数 # include <stdio.h> # include <algorithm> # include <iostream> # include <string.h> # include <math.h> using namespace std; char str[1010]; int a[1010]; int c[1010]; int main() { int k,m,i,tt,len,j; while(~scanf("%s %d",str,&m)) { len=strlen(str); for(i=0; i<len; i++) a[i]=str[i]-'0'; k=0; for(i=0;i<len-1&&m>0;i++) { if(a[i]<=a[i+1]) { c[k++]=a[i]; } else { m--; while(c[k-1]>a[i+1]&&m>0) { k--; m--; } } } for(;i<len;i++) c[k++]=a[i]; // for(i=0;i<k;i++) // printf("%d",c[i]); // printf("\n"); for(i=0;i<k-m;i++) { if(c[i]!=0) break; } if(i==k-m) printf("0"); else { for(j=i;j<k-m;j++) printf("%d",c[j]); } printf("\n"); } return 0; }
标签:blog io ar os sp for 2014 log amp
原文地址:http://blog.csdn.net/lp_opai/article/details/40947979