UVA10785 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 < N ≤ 250) 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

问题链接UVA10785 The Mad Numerologist
问题简述:(略)
问题分析
    字符串排序问题,暂不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10785 The Mad Numerologist */

#include <bits/stdc++.h>

using namespace std;

const int C1 = 21;
const int C2 = 5;
const char vowels[] = "AUEOI";
const char consonants[] = "JSBKTCLDMVNWFXGPYHQZR";

int main()
{
    int t, caseno = 0, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);

        string vowel, consonant;
        for(int i = 1, k = 0; i <= (n + 1) / 2; i++) {
            vowel += vowels[k];
            if(i % C1 == 0) k++;
        }
        for(int i = 1, k = 0; i <= n / 2; i++) {
            consonant += consonants[k];
            if(i % C2 == 0) k++;
        }
        sort(vowel.begin(), vowel.end());
        sort(consonant.begin(), consonant.end());

        printf("Case %d: ", ++caseno);
        for(int i = 1; i <=n; i++)
            printf("%c", i & 1 ? vowel[i / 2] : consonant[i / 2 - 1]);
        printf("\n");
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10390095.html
MAD