描述
给定一个字符串str和两个字符a,b,将str中ASCII码处于a,b之间(含a b)的字符按ASCII码从大到小排序,其他字符位置不变.输出排序后的字符串。
输入
输入只有两行:
第一行给出一个字符串str
第二行给出两个字符a,b,以一个空格间隔
字符串长度不大于 3000。
输出
输出只有一行,给出排序后的字符串。
样例输入
How many constest will be held during 2010 ?
0 9
0 9
样例输出
How many constest will be held during 2100 ?
题目来源
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
char a,b;
int main()
{
char ch[3000];
while(gets(ch))
{
cin>>a>>b;
int s=strlen(ch);
for(int i=0;i<s;i++)
{
if(ch[i]>=a&&ch[i]<=b)
{
for(int j=i+1;j<s;j++)
{
if(ch[j]>=a&&ch[j]<=b)
{
if(ch[i]<ch[j])
{
char t;
t=ch[i];
ch[i]=ch[j];
ch[j]=t;
}
}
}
}
}
for(int i=0;i<s;i++)
printf("%c",ch[i]);
// printf("\n");
// puts(ch);
}
return 0;
}