首页 > 其他 > 详细

UVA The Mad Numerologist

时间:2014-04-20 00:43:46      阅读:526      评论:0      收藏:0      [点我收藏+]

题目如下:

        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.

bubuko.com,布布扣
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".
bubuko.com,布布扣
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 <Nbubuko.com,布布扣250) that indicates howmany sets of inputs are there. Each of the nextN lines contains a single setof 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 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


本题看似高端,其实是道比较水的题,要求名字中的元音字母对应的数字之和最小和辅音字母对应的数字之和最小,并且在此条件下,该名字还应是字典序最小。思路是把元音字母和辅音字母与数字的对应用两个数组实现(只需要实现顺序即可并不需要知道具体对应的数字,因为只需要输出满足和最小的名字而不需要输出和),因为每个元音字母最多出现21次,而辅音最多出现5次,所以应对应时设置21个相同字母和5个相同字母,对名字数组中的每个位置,若是奇数,遍历元音数组,反之遍历辅音数组。这样就能满足和最小。再对得到的名字分别对元音和辅音排序,使之满足字典序最小。刚开始误认为只要遍历了数组,就一定是字典序最小,WA了,后来发现交换字母的顺序和不变但可以使字典序更小。

AC的代码如下:


UVA The Mad Numerologist,布布扣,bubuko.com

UVA The Mad Numerologist

原文:http://blog.csdn.net/u013840081/article/details/24133009

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!