题目:
Numerology is a science that is used by many people to findout a mans personality, sole purpose of life, desires to experience etc. Somecalculations of numerology are very complex, while others are quite simple. Youcan sit alone at home and do these easy calculations without taking any oneshelp. However in this problem you wont be asked to find the value of yourname.
To find the value of a name modern numerologists have assigned values to all theletters of English Alphabet. The table on the left shows the numerical valuesof all letters of English alphabets. Five letters A, E, I, O, U are vowels. Restsof the letters are consonant.In this table all letters in column 1 have value 1, allletters in column 2 have value 2 and so on. So T has value 2, F has value 6, Rhas value 9, O has value 6 etc. When calculating the value of a particular namethe consonants and vowels are calculated separately. The following pictureexplains this method using the name ``CHRISTOPHER RORY PAGE".
So you can see that to find the consonant value, the values of individualconsonants are added and to find the vowel value the values of individualvowels are added.A mad Numerologist suggests people many strange lucky names.He follows the rules stated below while giving lucky names.
- The name has a predefined length N.
- The vowel value and consonant value of the name must bekept minimum.
- To make the pronunciation of the name possible vowelsand consonants are placed in alternate positions. Actually vowels are put inodd positions and consonants are put in even positions. The leftmost letter ofa 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 fivetimes and no vowels can be used in a name more than twenty-one times
- Following the rules and limitations above the name mustbe kept lexicographically smallest. Please note that the numerologists firstpriority is to keep the vowel and consonant value minimum and then to make thename lexicographically smallest.
input
First line of the input file contains an integer N (0 < N250) that indicates howmany sets of inputs are there. Each of the next N lines contains a single setof input. The description of each set is given below:Each line contains an integer n (0 < n < 211) that indicates the predefined length of the name.
output
For each set of input produce one line of output. This linecontains the serial of output followed by the name that the numerologist wouldsuggest following the rules above. All letters in the output should beuppercase English letters.
sample input
3
1
5
5
sample output
Case 1: A
Case 2: AJAJA
Case 3: AJAJA
题解:将元音和辅音分开组成一个给定长度的单词,元音放奇数位置,辅音放偶数位置,根据表格,要求得到的所有字母代表的值的和最小,并且字母序最小。可以先把元音和辅音根据长度需要放置到两个字符串里,然后按字典序排序,最后两个字符串交叉组合得到结果。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const char y[6] = "AUEOI";
const char f[22] = "JSBKTCLDMVNWFXGPYHQZR";
string ans1, ans2, ans;
int main() {
int t, len;
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
ans1 = ans2 = ans = "";
scanf("%d", &len);
printf("Case %d: ", i);
int n = 0;
for (int j = 1; j <= (len + 1) / 2; j++) {
ans1 += y[n];
if (j % 21 == 0)
n++;
}
n = 0;
for (int j = 1; j <= len / 2; j++) {
ans2 += f[n];
if (j % 5 == 0)
n++;
}
sort(ans1.begin(), ans1.end());
sort(ans2.begin(), ans2.end());
for (int j = 1; j <= len; j++)
if (j % 2 == 1)
ans += ans1[j / 2];
else
ans += ans2[j / 2 - 1];
cout << ans << endl;
}
return 0;
}