链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183
一道字符串处理题,错了好多次。 字符串处理真的很考基本功。。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int N = 10000+100;
char str[N],str2[N];
int ans[N];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int i,j,k,m;
while(~scanf(" %s%d",str,&m))
{
memset(ans,0,sizeof(ans));
int len = strlen(str);
for(i=0; i<len; i++)
ans[i] = str[i] - '0';
for(i=0; i<m; i++)
{
for(j=0; j<len; j++)
{
if(ans[j] > 0)
{
for(k=j+1; k<len; k++)
if(ans[k] >= 0)
break;
if(ans[j] > ans[k])
{
ans[j] = -1;
break;
}
}
}
}
int flag = 0;
for(i=0; i<len; i++)
{
if(ans[i] != 0 && ans[i]!=-1)
flag = 1;
if(flag==1 && ans[i]!=-1)
printf("%d",ans[i]);
}
if(!flag)
printf("0");
printf("\n");
}
return 0;
}