UVa10785 The Mad Numerologist


 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 next N lines contains a single setof input. The description of each set is given below:Each line contains an integer n ( 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



Miguel Revilla2004-12-02

这题大意就是不同的字母有不同的权值,现给定一个长度,要求元音字母在奇数位,辅音字母在偶数位,且元音不超过21,辅音不超过5,要组成一个权值最小的字符串。直接把各个字母按照元音辅音分类,并按照权值大小和字典序排序,然后直接组合,最后再从新排序一此即可。

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const char vowel[5] = {'A','U','E','O','I'};
const char consonant[21] = {'J','S','B','K','T','C','L','D','M','V','N','W','F','X','G','P','Y','H','Q','Z','R'};

int main() {
	char ans_v[200];
	char ans_c[200];
	int Case;
	cin >> Case;
	for (int i = 0; i < Case; i++) {
		memset(ans_v,0,sizeof(ans_v));
		memset(ans_c,0,sizeof(ans_c));
		int num;		//number
		int v = 0;		//the v'th vowel
		int n_v = 0;	//the times of the v'th vowel
		int c = 0;		//the c'th consonant
		int n_c = 0;	//the times of the c'th consonant
		cin >> num;
		cout << "Case " << i+1 << ": ";
		for (int j = 0; j < num; j++) {
			if (j % 2 == 0) {
				ans_v[n_v] = vowel[v];
				n_v++;
				if (n_v % 21 == 0) {
					v++;
				}
			}
			else {
				ans_c[n_c] = consonant[c];
				n_c++;
				if (n_c % 5 == 0) {
					c++;
				}
			}
		}
		sort(ans_v,ans_v+n_v);
		sort(ans_c,ans_c+n_c);
		for (int j = 0; j < num; j++) {
			if (j % 2 == 0)
				cout << ans_v[j/2];
			else
				cout << ans_c[j/2];
		}
		cout << endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值