您的位置:首页 > 其它

UVA - 10785 The Mad Numerologist

2014-08-08 19:47 459 查看


 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.



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".



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

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

题意:
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>

using namespace std;
char a[] = "AUEOI";
char b[] = "JSBKTCLDMVNWFXGPYHQZR";
int cmp(const void *a, const void *b)
{
return *(char *)a - *(char *)b ;

}
int main(){
char ca[200];
char cb[200];

int n;
while(scanf("%d",&n ) != EOF)
{  int m ;
for(int i = 0 ; i < n ; i ++){
scanf("%d",&m);
memset(ca,0,200*sizeof(char));
memset(cb, 0 ,200* sizeof(char));
printf("Case %d: ", i+1);

int x  = 0;
int y = 0;
int k = 0 ;
int w = 0;
int count1 = 0 ;
int count2 = 0 ;

for(int i = 0 ; i < m/2 ; i++)
{
ca[count1 ++] = a[x];
cb[count2 ++] = b[y];
k ++ ;
w ++ ;
if(k == 21)
{
k = 0;
x ++ ;

}
if(w == 5)
{
w = 0;
y ++;

}

}
if(m % 2)
ca[count1 ++] = a[x];
qsort(ca,count1,sizeof(char),cmp);
qsort(cb,count2,sizeof(char),cmp);
for(int i = 0 ; i < m /2 ;i ++)
{
printf("%c%c",ca[i],cb[i]);

}

if(count1 > count2)
printf("%c",ca[count1 - 1]);
printf("\n");

}
}

return  0;

}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva UVA - 10785 The Mad