Posted on 2011-11-28 19:11
C小加 閱讀(250)
評論(0) 編輯 收藏 引用 所屬分類:
解題報告
月賽的一道水題,當時一直WA。后來問別人怎么做的時候發現自己把意思理解錯了。
因為給出的位數是固定的,如果你在整個字符串范圍內找到最大值后,會發現后邊的位數會變的不夠。所以找最大值的時候必須考慮到后邊的位數足夠。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAXN=103;
char s[MAXN];
int Search(int l,int r)
{
char c='0';
int pos=l;
for(int i=l;i<=r;i++)
{
if(c<s[i])
{
c=s[i];
pos=i;
}
}
return pos;
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
char ans[MAXN];
int n;
scanf("%s %d",s,&n);
int sn=strlen(s);
int st=sn-n;
int wos=0;
int i;
for(i=0;i<st;i++)
{
int cos=Search(wos,n+i);
ans[i]=s[cos];
wos=cos+1;
}
ans[i]='\0';
printf("%s\n",ans);
}
return 0;
}