UVA10785 The Mad Numerologist

来源:互联网 发布:js中动态生成表格 编辑:程序博客网 时间:2024/06/04 18:55


 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.
\epsfbox{p10785a.eps}
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".
\epsfbox{p10785b.eps}
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 <N$ \le$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 

3155

Sample Output 

Case 1: ACase 2: AJAJACase 3: AJAJA



这道题的题意是:按照上面那个奇数位 要放AEIOU 每个能放21次 ,偶数位放其他的,每个可以5次。。要把权重最小的先排。。但最后输出是要字典序输出。。

比如你排权重位1的J和S   AJAJAJAJAJASASASASASAB,但这样后,B要放在第一个偶数位置。


所以思路是按权重存两个字符串,原音字符串和辅音字符串。。然后两个都排序。在交叉输出。


AC代码:


#include<stdio.h>#include<string.h>#include<iostream>#include<stdlib.h>#include<map>using namespace std;int cmp (const void *p1 ,const void *p2) {return *((char*)p1) > *((char*)p2);}int main() {int time[200] = {0};char zy[5] = { 'A','U','E','O','I'};char fy[21] =  {'J','S','B','K','T','C','L','D','M','V','N','W','F','X','G','P','Y','H','Q','Z','R'};char yy[200];char ff[200];int t;int t1;cin >> t;int k = 1;while (t--) {for (int j = 0; j <200 ;j++) {ff[j] = '\0';yy[j] = '\0';time[j] = 0;}cin >> t1;int w = 0 ;int q = 0 ;printf("Case %d: ",k++);for ( int i = 0 ;i < t1; i++) {if(i % 2 == 0) {for (int j = 0; j < 5; j++) {if( time[zy[j]] < 21 ) {yy[w++] = zy[j];time[zy[j]] ++ ;break;}}}if(i % 2 != 0) {for (int j = 0; j < 21; j++) {if( time[fy[j]] < 5 ) {ff[q++] = fy[j];time[fy[j]] ++;break;}}}}w = 0;q = 0;if (t1 % 2 == 0) {qsort(yy,t1/2,sizeof(yy[0]),cmp);qsort(ff,t1/2,sizeof(ff[0]),cmp);}if(t1 % 2 != 0) {qsort(yy,t1/2 + 1,sizeof(yy[0]),cmp);qsort(ff,t1/2,sizeof(ff[0]),cmp);}for (int i = 0,k1 =0 ,k2 = 0 ;i < t1; i++) {if (i % 2 == 0 ) printf ("%c",yy[k1++]);elseprintf("%c",ff[k2++]);}cout << endl;}}


0 0
原创粉丝点击