10785 - The Mad Numerologist

Uvaoj

10785 - The Mad Numerologist


  The Mad Numerologist 
Numerology is a science that is used by many people to find out a mans personality, sole purpose of life, desires to experience etc. Some calculations of numerology are very complex, while others are quite simple. You can sit alone at home and do these easy calculations without taking any ones help. However in this problem you wont be asked to find the value of your name.
\epsfbox{p10785a.eps}
To find the value of a name modern numerologists have assigned values to all the letters of English Alphabet. The table on the left shows the numerical values of all letters of English alphabets. Five letters A, E, I, O, U are vowels. Rests of the letters are consonant. In this table all letters in column 1 have value 1, all letters in column 2 have value 2 and so on. So T has value 2, F has value 6, R has value 9, O has value 6 etc. When calculating the value of a particular name the consonants and vowels are calculated separately. The following picture explains this method using the name ``CHRISTOPHER RORY PAGE".
\epsfbox{p10785b.eps}
So you can see that to find the consonant value, the values of individual consonants are added and to find the vowel value the values of individual vowels 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 be kept minimum.
  • To make the pronunciation of the name possible vowels and consonants are placed in alternate positions. Actually vowels are put in odd positions and consonants are put in even positions. The leftmost letter of a 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 five times and no vowels can be used in a name more than twenty-one times
  • Following the rules and limitations above the name must be kept lexicographically smallest. Please note that the numerologists first priority is to keep the vowel and consonant value minimum and then to make the name lexicographically smallest.

Input 

First line of the input file contains an integer  N  (   0 < N$ \le$250 ) that indicates how many sets of inputs are there. Each of the next  N  lines contains a single set of 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 line contains the serial of output followed by the name that the numerologist would suggest following the rules above. All letters in the output should be uppercase English letters.

Sample Input 

3
1
5
5

Sample Output 

Case 1: A
Case 2: AJAJA
Case 3: AJAJA



Miguel Revilla 2004-12-02

题目意思之前我一直没懂,看了别人的代码才推出什么意思...
题目大意:第一个数字N代表测试样例的个数,接下来的N行每行有一个数字n,表示输出字母的个数,输出字母规则如下:
1、奇数位为元音字母,偶数位为辅音字母
2、字母选取的时候应选表格对应值小的字母,元音字母每个最多选21次,辅音字母最多每次最多选5次
3、最终输出字母,元音、辅音字母需按字典序排列输出。
例如:

Input:

1

43

22个元音字母选取的是AAAAAAAAAAAAAAAAAAAAAU(即21个A,一个U)、21个辅音字母选取的是JJJJJSSSSSBBBBBKKKKKT(即J、S、B、K分别为5个和1个T),但输出是需是字典序的,然后元音奇数位、辅音偶数位输出。

Output:

Case 1: ABABABABABAJAJAJAJAJAKAKAKAKAKASASASASASATU 

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 110
using namespace std;
const char x[] = "AUEOI";
const char y[] = "JSBKTCLDMVNWFXGPYHQZR";
int main(){
	int t, n;
	char p[N], q[N];
	scanf("%d", &t);
	for (int cas = 1; cas <= t; cas++){
		scanf("%d",&n);
		int xi=n-n/2,yi=n/2;
		for(int i=0;i<xi;i++)
			p[i]=x[i/21];
		for(int i=0;i<yi;i++)
			q[i]=y[i/5];
		sort(p, p + xi);
		sort(q, q + yi);
		printf("Case %d: ", cas);
		for (int i = 0,j=0,k=0; i < n; i++)
			if(i%2)
				putchar(q[j++]);
			else
				putchar(p[k++]);
		printf("\n");
	}
	return 0;
}


猜你喜欢

转载自blog.csdn.net/guduyibeizi/article/details/9666443
MAD