uva 10785 - 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 < N250) 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

思路

字母量小,用硬编码制定移动路径,在排序上如果是C语言可用Qsort,当然这里自己编写计数排序效率更好.

解答

#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 DEBUG
ifstream 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;
}

uva 10785 - The Mad Numerologist,布布扣,bubuko.com

时间: 2024-11-11 11:01:33

uva 10785 - The Mad Numerologist的相关文章

小白书练习题5.5.3 排序检索类、

UVA 340 Master-Mind Hints 题意:猜数字游戏,给n个数的序列给你.接下来一行是答案序列.剩下的都是猜测序列.对于每一个猜测序列,统计有多少个数字相同并且位置相同.有多少数字相同位置不同.每一个数字只能用一次. 思路:直接统计可以求出数字相同并且位置相同的哪一些数.在此过程中我加了一个标记数组.标记那些用过的数的位置为1,没用过为0:然后枚举猜测中哪些没用过的数字.去答案序列中找.当数字相等并且答案行中那个数也没用过时.计数加1: 1 #include<cstdio> 2

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

UVA 10110 Light, more light【经典开灯问题】

Light, more light Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 10110 64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Type: None None Graph Theory      

Light, more light UVA 10110

说说:题意大概就是给定一个数n,然后从1遍历到n,原本要输出的状态是no,然后再遍历过程中遇到n的因子就变一次状态.最后将最终的状态输出.解法的话,将这个过程模拟一遍也是可以的.但我们知道若n能被m整出,那么也必定能被n/m整除,所以若n不是平方数的话状态肯定变换偶数次.照这个思路,代码的效率也就提高不少啦~ 题目: Light, more light The Problem There is man named "mabu" for switching on-off light in

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B