您的位置:首页 > 其它

南邮 OJ 1181 字符排序

2015-08-05 10:30 337 查看


字符排序

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 826            测试通过 : 184 

比赛描述

给定一个字符串str和两个字符a,b,将str中ASCII码处于a,b之间(含a
b)的字符按ASCII码从大到小排序,其他字符位置不变.输出排序后的字符串。

输入

输入只有两行:
第一行给出一个字符串str

第二行给出两个字符a,b,以一个空格间隔
 
字符串长度不大于3000。

输出

输出只有一行,给出排序后的字符串。

样例输入

How many constest will be held during 2010 ?

0 9

样例输出

How many constest will be held during 2100 ?

提示

 

题目来源

李鸿斌(honghu)

#include<stdio.h>
#include<algorithm>
#define N 3000
using namespace std;

int main(){
char str[3000],str2[3000],a,b;
int idx[3000];
int i,j,k,n;
for(n=0;n<N;++n){
scanf("%c",&str
);
if(str
=='\0' || str
=='\n'){
break;
}
}
scanf("%c %c",&a,&b);
if(a>b){
a ^= b;
b ^= a;
a ^= b;
}
for(i=0,j=0;i<n;++i){
if(str[i]>=a && str[i]<=b){
str2[j] = str[i];
idx[j++] = i;
}
}
sort(str2,str2+j);
for(k=0;k<j;++k){
str[idx[k]] = str2[j-1-k];
}
for(i=0;i<n;++i){
printf("%c",str[i]);
}
putchar('\n');
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  南邮OJ ACM 字符排序