UVa 10785 - 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

题目大意:

要求构造一姓名, 规则如下:

  1. 长度为 n。
  2. consonant values 和 vowel values 为最小值。
  3. 从左往右, 从 1 开始计数, 奇数位置必须为元音字母, 偶数位置则为辅音字母。
  4. 同样一个元音字母, 最多出现 21 次; 同样一个辅音字母, 最多出现 5 次。
  5. 符合以上规则的条件下, 要求字典序最小。

题目解析:

由于元音和辅音之间互不干涉, 且规则相似, 所以可以分开来做 。

先将需要用到的元音放到一个字符串中, 值最小的优先。

然后对该字符串排序, 则可以保证 vowel values 最小, 且字典序最小。

辅音的做法类似, 最后将构造出来的两个字符串合并即可。


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;

char vowels[] = "AUEOI";
char conson[] = "JSBKTCLDMVNWFXGPYHQZR";

int main() {
	int t;
	while(cin >> t) {
		for(int i=1;i<=t;i++) {
			int n;
			cin >> n;
			
			string vow,con;
			
			for(int j=1,pos=0;j<=(n+1)/2;j++) {
				vow += vowels[pos];
				if(j%21 == 0) {	
					pos++;	
				}
			}
			
			for(int j=1,pos = 0;j<=n/2;j++) {
				con += conson[pos];		
				if(j%5 == 0) {	
					pos++;	
				}	
			}
			
			sort(vow.begin(),vow.end());
			sort(con.begin(),con.end());
			

			cout<<"Case "<<i<<": ";
			int t1=0,t2=0;
			for(int j=0;j<n;j++) {
				if(j%2 == 0)
					cout<<vow[t1++];
				else
					cout<<con[t2++];
			}
			cout<<endl;
		}	
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值