10785 - The Mad Numerologist
Time limit: 3.000 seconds
Numerology is a science that is used by many people to find out a mans personality, sole purpose of life, desires to experience etc. Some calculations of numerology are very complex, while others are quite simple. You can sit alone at home and do these easy calculations without taking any ones help. However in this problem you wont be asked to find the value of your name.


- The name has a predefined length N.
- The vowel value and consonant value of the name must be kept minimum.
- To make the pronunciation of the name possible vowels and consonants are placed in alternate positions. Actually vowels are put in odd positions and consonants are put in even positions. The leftmost letter of a name has position 1; the position right to it is position 2 and so on.
- No consonants can be used in a name more than five times and no vowels can be used in a name more than twenty-one times
- Following the rules and limitations above the name must be kept lexicographically smallest. Please note that the numerologists first priority is to keep the vowel and consonant value minimum and then to make the name lexicographically smallest.
Input
First line of the input file contains an integer N ( 0 < N
Output
For each set of input produce one line of output. This line contains the serial of output followed by the name that the numerologist would suggest following the rules above. All letters in the output should be uppercase English letters.Sample Input
3 1 5 5
Sample Output
Case 1: A Case 2: AJAJA Case 3: AJAJA
注意最后确定基本答案后要奇偶分别排序。
完整代码:
/*0.015s*/
#include<cstdio>
#include<algorithm>
using namespace std;
const char vowel[] = {"AUEOI"};
const char con[] = {"JSBKTCLDMVNWFXGPYHQZR"};
char oddans[110], evenans[110], ans[220];
int main()
{
int t, cas, i, n, f1, f2;
scanf("%d", &t);
for (cas = 1; cas <= t; ++cas)
{
printf("Case %d: ", cas);
scanf("%d", &n);
for (i = 1; i <= n; ++i)
{
if (i & 1)
oddans[(i >> 1)] = vowel[i / 42];
else
evenans[(i - 1) >> 1] = con[(i - 2) / 10];///计算
}
f1 = (n & 1 ? (n >> 1) + 1 : (n >> 1)), f2 = n >> 1;
sort(oddans, oddans + f1);
sort(evenans, evenans + f2);///排序
for (i = 0; i < f1; ++i)
ans[i << 1] = oddans[i];
for (i = 0; i < f2; ++i)
ans[(i << 1) + 1] = evenans[i];///重填
ans[n] = 0;
puts(ans);
}
return 0;
}