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 |
![\epsfbox{p10785a.eps}](http://uva.onlinejudge.org/external/107/p10785a.jpg)
![\epsfbox{p10785b.eps}](http://uva.onlinejudge.org/external/107/p10785b.jpg)
- 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$](http://uva.onlinejudge.org/external/107/10785img3.png)
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
这道题的题意是:按照上面那个奇数位 要放AEIOU 每个能放21次 ,偶数位放其他的,每个可以5次。。要把权重最小的先排。。但最后输出是要字典序输出。。
比如你排权重位1的J和S AJAJAJAJAJASASASASASAB,但这样后,B要放在第一个偶数位置。
所以思路是按权重存两个字符串,原音字符串和辅音字符串。。然后两个都排序。在交叉输出。
AC代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<map>
using namespace std;
int cmp (const void *p1 ,const void *p2) {
return *((char*)p1) > *((char*)p2);
}
int main() {
int time[200] = {0};
char zy[5] = { 'A','U','E','O','I'};
char fy[21] = {'J','S','B','K','T','C','L','D','M','V','N','W','F','X','G','P','Y','H','Q','Z','R'};
char yy[200];
char ff[200];
int t;
int t1;
cin >> t;
int k = 1;
while (t--) {
for (int j = 0; j <200 ;j++) {
ff[j] = '\0';
yy[j] = '\0';
time[j] = 0;
}
cin >> t1;
int w = 0 ;
int q = 0 ;
printf("Case %d: ",k++);
for ( int i = 0 ;i < t1; i++) {
if(i % 2 == 0) {
for (int j = 0; j < 5; j++) {
if( time[zy[j]] < 21 ) {
yy[w++] = zy[j];
time[zy[j]] ++ ;
break;
}
}
}
if(i % 2 != 0) {
for (int j = 0; j < 21; j++) {
if( time[fy[j]] < 5 ) {
ff[q++] = fy[j];
time[fy[j]] ++;
break;
}
}
}
}
w = 0;
q = 0;
if (t1 % 2 == 0) {
qsort(yy,t1/2,sizeof(yy[0]),cmp);
qsort(ff,t1/2,sizeof(ff[0]),cmp);
}
if(t1 % 2 != 0) {
qsort(yy,t1/2 + 1,sizeof(yy[0]),cmp);
qsort(ff,t1/2,sizeof(ff[0]),cmp);
}
for (int i = 0,k1 =0 ,k2 = 0 ;i < t1; i++) {
if (i % 2 == 0 )
printf ("%c",yy[k1++]);
else
printf("%c",ff[k2++]);
}
cout << endl;
}
}