(TOJ1506)Sort ZOJ7

描述

Given a string of no more than 1000 characters. You are supposed to sort the characters into a substring of all Z's followed by O's, J's, 7's, and the rest of the other characters.

输入

Each case gives a string described by the problem. The string given contains no space.

输出

For each test case, output the resulting string. Note the order of the characters other than Z, O, J and 7 must be kept after sorting.

样例输入

t7ZJ7OhO7B7O7irZtOhZdayJ77

样例输出

ZZZOOOOJJ7777777thBirthday
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<ctype.h>
 4 #include<math.h>
 5 
 6 char a[1001],b[1001];
 7 
 8 void deal(char *s)
 9 {
10     int i,len,c1,c2,c3,c4,j,k;
11     c1=c2=c3=c4=j=0;
12     len=strlen(s);
13     for(i=0; i<len; i++){
14         switch(s[i]){
15             case'Z':c1++;break;
16             case'O':c2++;break;
17             case'J':c3++;break;
18             case'7':c4++;break;
19             default:b[j++]=a[i];break;
20         }
21     }
22     for(k=0; k<c1; k++) printf("Z");
23     for(k=0; k<c2; k++) printf("O");
24     for(k=0; k<c3; k++) printf("J");
25     for(k=0; k<c4; k++) printf("7");
26     for(k=0; k<j; k++) printf("%c",b[k]);
27     printf("\n");
28 }
29 
30 void solve()
31 {
32     while(gets(a)){
33         deal(a);
34     }
35 }
36 
37 int main()
38 {
39     solve();
40     return 0;
41 }
 

转载于:https://www.cnblogs.com/xueda120/archive/2013/05/20/3089204.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值