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.
The Mad Numerologist |
- 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 < N250) 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 长度为 n consonant values 和 vowel values 为最小值 从左往右, 从 1 开始计数, 奇数位置为元音字母, 偶数位置则为辅音字母 同样一个元音字母, 最多出现 21 次; 同样一个辅音字母, 最多出现 5 次 符合以上规则的条件下, 要求字典序最小。输入 n, 输出符合规则的姓名。
先将需要用到的元音放到一个字符串中, 值最小的优先。
然后对该字符串排序, 则可以保证 元音 序列 最小, 且字典序最小。
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<string.h> using namespace std; char a[] = "AUEOI"; char b[] = "JSBKTCLDMVNWFXGPYHQZR"; int cmp(const void *a, const void *b) { return *(char *)a - *(char *)b ; } int main(){ char ca[200]; char cb[200]; int n; while(scanf("%d",&n ) != EOF) { int m ; for(int i = 0 ; i < n ; i ++){ scanf("%d",&m); memset(ca,0,200*sizeof(char)); memset(cb, 0 ,200* sizeof(char)); printf("Case %d: ", i+1); int x = 0; int y = 0; int k = 0 ; int w = 0; int count1 = 0 ; int count2 = 0 ; for(int i = 0 ; i < m/2 ; i++) { ca[count1 ++] = a[x]; cb[count2 ++] = b[y]; k ++ ; w ++ ; if(k == 21) { k = 0; x ++ ; } if(w == 5) { w = 0; y ++; } } if(m % 2) ca[count1 ++] = a[x]; qsort(ca,count1,sizeof(char),cmp); qsort(cb,count2,sizeof(char),cmp); for(int i = 0 ; i < m /2 ;i ++) { printf("%c%c",ca[i],cb[i]); } if(count1 > count2) printf("%c",ca[count1 - 1]); printf("\n"); } } return 0; }