首页 > 其他分享 >UVa 10785 The Mad Numerologist (排序)

UVa 10785 The Mad Numerologist (排序)

时间:2023-04-12 11:37:37浏览次数:39  
标签:consonants letters name Numerologist vowels value Mad UVa find


10785 - The Mad Numerologist

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=1726

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


315
5


Sample Output


Case 1: ACase 2: AJAJACase 3: AJAJA



注意最后确定基本答案后要奇偶分别排序。


完整代码:

/*0.015s*/

#include<cstdio>
#include<algorithm>
using namespace std;
const char vowel[] = {"AUEOI"};
const char con[] = {"JSBKTCLDMVNWFXGPYHQZR"};

char oddans[110], evenans[110], ans[220];

int main()
{
	int t, cas, i, n, f1, f2;
	scanf("%d", &t);
	for (cas = 1; cas <= t; ++cas)
	{
		printf("Case %d: ", cas);
		scanf("%d", &n);
		for (i = 1; i <= n; ++i)
		{
			if (i & 1)
				oddans[(i >> 1)] = vowel[i / 42];
			else
				evenans[(i - 1) >> 1] = con[(i - 2) / 10];///计算
		}
		f1 = (n & 1 ? (n >> 1) + 1 : (n >> 1)), f2 = n >> 1;
		sort(oddans, oddans + f1);
		sort(evenans, evenans + f2);///排序
		for (i = 0; i < f1; ++i)
			ans[i << 1] = oddans[i];
		for (i = 0; i < f2; ++i)
			ans[(i << 1) + 1] = evenans[i];///重填
		ans[n] = 0;
		puts(ans);
	}
	return 0;
}



标签:consonants,letters,name,Numerologist,vowels,value,Mad,UVa,find
From: https://blog.51cto.com/u_5535544/6185331

相关文章

  • UVa 10344 23 out of 5 (全排列枚举&回溯)
    10344-23outof5Timelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1285Yourtaskistowriteaprogramthatcandecidewhetheryoucanfindanarithmetic......
  • UVa 11205 The broken pedometer (枚举好题&巧用二进制)
    11205-ThebrokenpedometerTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=2146TheProblemAmarathonrunnerusesapedometerwithwhichheishavingpro......
  • UVa 10167 Birthday Cake (枚举)
    10167-BirthdayCakeTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=1108BackgroundLucyandLilyaretwins.Todayistheirbirthday.Motherbuysabirthd......
  • UVa 129 Krypton Factor (回溯好题)
    129-KryptonFactorTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=65YouhavebeenemployedbytheorganisersofaSuperKryptonFactorContestinwhichcontestantshaveveryhighmental......
  • UVa 11210 Chinese Mahjong (模拟&枚举&回溯)
    11210-ChineseMahjongTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2151Mahjong()isagameofChineseoriginusuallyplayedbyfourpersonswithtilesresemblingdominoesandbearing......
  • UVa 11375 Matches (DP&高精度)
    11375-MatchesTimelimit:2.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2370Wecanmakedigitswithmatchesasshownbelow:Given N matches,findthenumberofdifferentnumbersrepresentableusing......
  • UVa 11507 Bender B. Rodríguez Problem (模拟&异或)
    11507-BenderB.RodríguezProblemTimelimit:4.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2502Benderisarobotbuiltby Mom'sFriendlyRobotCompany atits......
  • UVa 443 / POJ 2247 Humble Numbers (4因子-丑数&STL灵活运用)
    443-HumbleNumbersTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=384http://poj.org/problem?id=2247Anumberwhoseonlyprimefactorsare2,3,5or7isc......
  • UVa 10673 Play with Floor and Ceil (数论)
    10673-PlaywithFloorandCeilTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1614TheoremForanytwointegers x and k thereexiststwomoreintegers p ......
  • UVa 10004 Bicoloring (DFS&二分图)
    10004-BicoloringTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=945In1976the``FourColorMapTheorem"wasprovenwiththeassistanceofacomput......