uva 10785 - 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.
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".
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 #include 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

    좋은 웹페이지 즐겨찾기