UVA 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.
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".
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 < N250 ) 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

这题完全是在考英语嘛!!!!!其实知道题意就很水有木有。。。ffffuck。。

题目意思:输入一个n值。。然后接下去n位。奇数位放元音(AUEOI),偶数位放辅音(JSBKTCLDMVNWFXGPYHQZR)。 注意顺序。。是按题目中给出表格从列到行的顺序。。。

每个元音能放最多21次。每个辅音5次;

然后放完之后。要输出字典序最小的排序。。。。

WA了次。。因为末尾多输出一个'\0'没有注意。。。坑啊

方法就是 建2个数组。一个存奇数位的字母,一个存偶数位的字母。。。

存完之后 2个数组都进行字典序排序。。

然后同时输出2个数组即可。。


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

char yuan[6] = {"AUEOI"};
char fu[22] = {"JSBKTCLDMVNWFXGPYHQZR"};
int t;
int n;
char out1[250];
char out2[250];
int main()
{
	scanf("%d", &t);
	int tt = 1;
	while (t --)
	{
		int i;
		int y = 0;
		int f = 0;
		int numy = 0;
		int numf = 0;
		memset(out1, 0, sizeof(out1));
		memset(out2, 0, sizeof(out2));
		scanf("%d", &n);
		for (i = 0; i < n; i ++)
		{
			if (numy == 21)
			{
				y ++;
				numy = 0;
			}
			if (numf == 5)
			{
				f ++;
				numf = 0;
			}
			if (i % 2 == 0)
			{
				out1[i/2] = yuan[y];
				numy ++;
			}
			else
			{
				out2[i/2] = fu[f];
				numf ++;
			}
		}
		out1[(n + 1)/2] = '\0';
		out2[n/2] = '\0';
		sort(out1, out1 + (n + 1) / 2);
		sort(out2, out2 + n / 2);
		printf("Case %d: ", tt ++);
		for (i = 0; i < (n + 1) / 2; i ++)
		{
			if (out1[i] != '\0')
				printf("%c",out1[i]);
			if (out2[i] != '\0')
				printf("%c", out2[i]);
		}
		printf("\n");
	}
	return 0;
}




你可能感兴趣的:(UVA 10785 The Mad Numerologist)