The Mad Numerologist
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.
The Mad Numerologist |
- 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
Miguel Revilla2004-12-02
这题大意就是不同的字母有不同的权值,现给定一个长度,要求元音字母在奇数位,辅音字母在偶数位,且元音不超过21,辅音不超过5,要组成一个权值最小的字符串。直接把各个字母按照元音辅音分类,并按照权值大小和字典序排序,然后直接组合,最后再从新排序一此即可。
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const char vowel[5] = {'A','U','E','O','I'};
const char consonant[21] = {'J','S','B','K','T','C','L','D','M','V','N','W','F','X','G','P','Y','H','Q','Z','R'};
int main() {
char ans_v[200];
char ans_c[200];
int Case;
cin >> Case;
for (int i = 0; i < Case; i++) {
memset(ans_v,0,sizeof(ans_v));
memset(ans_c,0,sizeof(ans_c));
int num; //number
int v = 0; //the v'th vowel
int n_v = 0; //the times of the v'th vowel
int c = 0; //the c'th consonant
int n_c = 0; //the times of the c'th consonant
cin >> num;
cout << "Case " << i+1 << ": ";
for (int j = 0; j < num; j++) {
if (j % 2 == 0) {
ans_v[n_v] = vowel[v];
n_v++;
if (n_v % 21 == 0) {
v++;
}
}
else {
ans_c[n_c] = consonant[c];
n_c++;
if (n_c % 5 == 0) {
c++;
}
}
}
sort(ans_v,ans_v+n_v);
sort(ans_c,ans_c+n_c);
for (int j = 0; j < num; j++) {
if (j % 2 == 0)
cout << ans_v[j/2];
else
cout << ans_c[j/2];
}
cout << endl;
}
return 0;
}