(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 }
 
作者:xueda120
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文地址:https://www.cnblogs.com/xueda120/p/3089204.html