标签:
请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大,
比如当n=92081346718538,m=10时,则新的最大数是9888
2 92081346718538 10 1008908 5
9888 98
思路:参考博客http://blog.csdn.net/niushuai666/article/details/7020056
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int T,m,lenn,i,j,location,max,copy[120],g;
char n[120];
cin>>T;
while(T--)
{
max=-1;
g=0;
location=0;
cin>>n>>m;
lenn=strlen(n);
for(i=0;i<lenn-m;i++)// lenn-m表示要求保留的位数
{
max=-1;
for(j=location;j<=m+i;j++)
{
if(n[j]-'0'>max)
{
max=n[j]-'0';
location=j;
}
}
copy[g++]=max;
location+=1;
}
for(i=0;i<g;i++)
cout<<copy[i];
cout<<endl;
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/zuguodexiaoguoabc/article/details/44938561