CodeChef Inscription 2013 Wonderland jewellery(简单题)

题目链接:http://www.codechef.com/INSCRP13/problems/INSCTS3

简单题就不多说了,就是标记单个字母次数然后按奇数偶数顺序输出。

代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 
 6 char str[1000100];
 7 
 8 int main()
 9 {
10 //    freopen("in.txt", "r", stdin);
11 
12     int n, flag[30];
13     scanf("%d", &n);
14     for(int cnt=0; cnt<n; cnt++){
15         scanf("%s", str);
16         memset(flag, 0, sizeof flag);
17         int len = strlen(str);
18         for(int i=0; i<len; i++){
19             flag[str[i]-'a']++;
20         }
21         for(int i=0; i<26; i++){
22             if(flag[i] && flag[i]%2==1){
23                 for(int j=0; j<flag[i]; j++){
24                     printf("%c", char('a'+i));
25                 }
26             }
27         }
28         for(int i=0; i<26; i++){
29             if(flag[i] && flag[i]%2==0){
30                 for(int j=0; j<flag[i]; j++){
31                     printf("%c", char('a'+i));
32                 }
33             }
34         }
35         printf("
");
36     }
37     return 0;
38 }
View Code
奔跑吧!少年!趁着你还年轻
原文地址:https://www.cnblogs.com/shu-xiaohao/p/3391638.html