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.
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 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$](http://uva.onlinejudge.org/external/107/10785img3.png)
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
题目大意:给出一个n,输出n位字母,奇数位放元音字母,偶数位放辅音字母,填充的顺序按题目所给出的字母表顺序,要注意的是:1、生的一个n位的字符串,它的奇数位和偶数位要分别按照字典序排列, 因为填充顺序在前的字典序不一定优先。2、元音字母每个最多使用21次,辅音每个最多使用5次(保证奇偶数量一致,题目要求)
解题思路:将奇偶位分别开一个数组,填充完字符后在用sort排序,然后交替输出。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 220
const char x[] = "AUEOI";
const char y[] = "JSBKTCLDMVNWFXGPYHQZR";
int main(){
int t, n;
char p[N], q[N];
scanf("%d", &t);
for (int k = 1; k <= t; k++){
// Init.
memset(p, 0, sizeof(p));
memset(q, 0, sizeof(q));
// Read.
scanf("%d", &n);
int xi = (n + 1) / 2, yi = n / 2;
// 奇数位>=偶数位。
for (int i = 0; i < xi; i++){
p[i] = x[i / 21];
if (i < yi)
q[i] = y[i / 5];
}
p[xi] = '\0';
q[yi] = '\0';
sort(p, p + xi);
sort(q, q + yi);
printf("Case %d: ", k);
for (int i = 0; i < xi; i++){
printf("%c", p[i]);
if (i < yi)
printf("%c", q[i]);
}
printf("\n");
}
return 0;}