Ultraviolet A 10785-the mad numerologist

Source: Internet
Author: User
Question

Numerology is a science that is used by province 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 particle 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 should strange lucky names. he follows the rules stated below while giving lucky names.

  • The name has a predefined LengthN.

  • 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 should smallest. Please note that the numerologists first priority is to keep the vowel and consonant value minimum and then to make the name should smallest.

Input

First line of the input file contains an integerN(0 <N250) that indicates how many sets of inputs are there. Each of the nextNLines contains a single set of input. The description of each set is given below: each line contains an integerN(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 wocould suggest following the rules above. all letters in the output shoshould be uppercase English letters.

Sample Input
3155

Sample output
Case 1: ACase 2: AJAJACase 3: AJAJA


Ideas

The number of letters is small, and the mobile path is hard-coded. If the sorting is in C language, qsort can be used. Of course, the efficiency of counting sorting is better here.

Answer
#include <iostream>#include <cstring>#include <string>#include <cstring>#include <fstream>#include <sstream>#include <vector>#include <cstdlib>#include <cstdio>#include <map>#include <algorithm>using namespace std;#ifdef DEBUGifstream in;ofstream out;#endif#ifdef DEBUG#define inpath      "./in.txt"#define outpath     "./out.txt"#define CIN     in#define COUT    out#else#define CIN     cin#define COUT    cout#endif/**move way*/const char *conList  = "JSBKTCLDMVNWFXGPYHQZR";const char *voList   =  "AUEOI";int main(){#ifdef DEBUG    in.open(inpath,     ios::in);    out.open(outpath,   ios::out);    if(in.fail()){            cout << "input init fail " << "\n";            return -1;    }    if(out.fail()){             cout << "output init fail " << "\n";            return -1;    }#endif    string ans;    string vans;    string cans;    int cases;    int len;    const char *wt[2];     CIN >> cases;     for(int currCase = 1; currCase <= cases; currCase++){        CIN >> len;        const char *vv = voList;        const char *cc = conList;        ans.clear();        vans.clear();        cans.clear();        for(int i = 1; i <= ((1 + len) >>1); i++){                    vans += *vv;                    if(i%21 == 0)                            vv++;        }        for(int i = 1; i <= (len>>1) ; i++){                    cans += *cc;                    if(i%5 == 0)                            cc++;        }        sort(vans.begin(), vans.end());        sort(cans.begin(), cans.end());        string::iterator viter = vans.begin();        string::iterator citer = cans.begin();        for(int lenCurr = 1; lenCurr <= len; lenCurr++){                    if(lenCurr&0x1)                            ans += *viter++;                    else                            ans += *citer++;        }        COUT << "Case " << currCase << ": " << ans << endl;        /*Case 1: A*/     }return 0;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.