The Mad Numerologist
The Mad Numerologist |
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.
![\epsfbox{p10785a.eps}](http://uva.onlinejudge.org/external/107/p10785a.jpg)
To find the value of a name modern numerologists have assigned values to all the letters of English Alphabet. The table on the left shows the numerical values of all letters of English alphabets. Five letters A, E, I, O, U are vowels. Rests of the letters are consonant. In this table all letters in column 1 have value 1, all letters in column 2 have value 2 and so on. So T has value 2, F has value 6, R has value 9, O has value 6 etc. When calculating the value of a particular name the consonants and vowels are calculated separately. The following picture explains this method using the name ``CHRISTOPHER RORY PAGE".
![\epsfbox{p10785b.eps}](http://uva.onlinejudge.org/external/107/p10785b.jpg)
So you can see that to find the consonant value, the values of individual consonants are added and to find the vowel value the values of individual vowels 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 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 < N250) that indicates how many sets of inputs are there. Each of the nextN lines contains a single set of input. The description of each set is given below: Each line contains an integern ( 0 < n < 211) that indicates the predefined length of the name.
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
给出26个字母的权值按要求构造长度为n的序列:
1字符串总权值最小
2奇数位置为元音偶数位置为辅音
3元音可以用21次辅音可以用5次·
4按字典序最小构造
开始以为最后一个条件没注意直接构造完就输出了,应该先按照贪心法选出所需字母,然后再按字典序排序即可。
#include<stdio.h>
#include<string.h>
char s1[6]="AUEOI",s2[22]="JSBKTCLDMVNWFXGPYHQZR",s[250][250],ch;
int ok(int k,int n,int m)
{int i;
if (((m-n)%2==0)&&(s[k][n]>s[k][m])) return 1;
return 0;
};
void main()
{ int use1[6],use2[22],a[6],b[21],i,j,k,n,pos1,pos2;
for (i=0;i<5;i++)
a[i]=21;
for (i=0;i<21;i++)
b[i]=5;
for (k=1;k<211;k++)
{pos1=0; pos2=0;
for (i=0;i<5;i++)
use1[i]=a[i];
for (i=0;i<21;i++)
use2[i]=b[i];
for (i=1;i<=k;i++)
{if (i%2==1) {while ((pos1<5)&&(use1[pos1]==0)) ++pos1; --use1[pos1]; s[k][i-1]=s1[pos1];}
else {while ((pos2<21)&&(use2[pos2]==0)) ++pos2; --use2[pos2]; s[k][i-1]=s2[pos2];}
}
s[k][k]='\0';
for (i=1;i<k-1;i++)
for (j=i+1;j<k;j++)
if (ok(k,i,j)) {ch=s[k][i];s[k][i]=s[k][j];s[k][j]=ch;}
}
scanf("%d",&n);
for (i=1;i<=n;i++)
{scanf("%d",&k);
printf("Case %d: %s\n",i,s[k]);
}
}