博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 10785 - The Mad Numerologist
阅读量:6006 次
发布时间:2019-06-20

本文共 4212 字,大约阅读时间需要 14 分钟。

hot3.png

题目

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.

\epsfbox{p10785a.eps}

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".

\epsfbox{p10785b.eps}

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$ \le$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 

3155

Sample Output 

Case 1: ACase 2: AJAJACase 3: AJAJA

思路

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

解答

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
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;}

转载于:https://my.oschina.net/u/572632/blog/305318

你可能感兴趣的文章
《FLUENT 14.0超级学习手册》——2.5 FLUENT 14.0的基本操作
查看>>
《Photoshop修色圣典——PPW专业照片修正流程与技巧》—第1章关于历史
查看>>
当我发现电脑有灵魂
查看>>
《 Apache Spark机器学习.》导读
查看>>
在openSUSE 13.1中配置FTP服务器
查看>>
如何使用 Docker 快速配置数据科学开发环境?
查看>>
《ELK Stack权威指南(第2版)》一3.6 Java日志
查看>>
C++流的streambuf详解及TCP流的实现
查看>>
《WebGL入门指南》——第1章,第1.4节本章小结
查看>>
Angular从零到一1.6 引导过程
查看>>
《iOS 6核心开发手册(第4版)》——1.1节触摸
查看>>
《C#多线程编程实战(原书第2版)》——2.5 使用AutoResetEvent类
查看>>
《量化金融R语言初级教程》一2.5 协方差矩阵中的噪声
查看>>
并发网每月TOP10文章
查看>>
黑客究竟用什么姿势偷走了你的钱? | 硬创公开课
查看>>
超越Hadoop的大数据分析之第一章介绍:为什么超越Hadoop Map-Reduce
查看>>
暗渡陈仓:用低消耗设备进行破解和渗透测试3.6 本章附录:深入分析安装脚本...
查看>>
自己动手构造编译系统:编译、汇编与链接2.5 链接程序的设计
查看>>
深入SQLServer日志收缩
查看>>
Serverless日志处理挑战与方案
查看>>