虽然是sorting的压轴,但是比起前面真心水题。这个专题结合前面string的很多,排序相对简单了,qsort基本解决。

题目:

  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

Miguel Revilla 2004-12-02

题目:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 char con[10][5],vow[10],n0[150],n1[150];
 5 int cmp_char(const void *a,const void *b)
 6 {
 7     return *(char*)a-*(char*)b;
 8 }
 9 void doit()
10 {
11     sprintf(con[0],"%s","JS");
12     sprintf(con[1],"%s","BKT");
13     sprintf(con[2],"%s","CL");
14     sprintf(con[3],"%s","DMV");
15     sprintf(con[4],"%s","NW");
16     sprintf(con[5],"%s","FX");
17     sprintf(con[6],"%s","GPY");
18     sprintf(con[7],"%s","HQZ");
19     sprintf(con[8],"%s","R");
20     vow[0]='A';
21     vow[1]='U';
22     vow[2]='E';
23     vow[3]='O';
24     vow[4]='I';
25 }
26 int main()
27 {
28     doit();
29     int n,now=0,cn,vn;
30     scanf("%d",&n);
31     while(n--)
32     {
33         cn=5,vn=21;
34         int t,i,cp=0,vp=0,p0=0,p1=0,jj=0;
35         scanf("%d",&t);
36         for(i=0;i<t;i++)
37         {
38             if((i+1)%2==0)
39             {
40                 n0[p0]=con[cp][jj];
41                 p0++;
42                 cn--;
43                 if(cn==0)
44                 {
45                     cn=5;
46                     jj++;
47                     if(con[cp][jj]=='\0')
48                     {
49                         cp++;
50                         jj=0;
51                     }
52                 }
53             }
54             else
55             {
56                 n1[p1]=vow[vp];
57                 p1++;
58                 vn--;
59                 if(vn==0)
60                 {
61                     vn=21;
62                     vp++;
63                 }
64             }
65         }
66         n1[p1]='\0';
67         n0[p0]='\0';
68         qsort(n1,p1,sizeof(char),cmp_char);
69         qsort(n0,p0,sizeof(char),cmp_char);
70         printf("Case %d: ",++now);
71         p1=0;
72         p0=0;
73         for(i=0;i<t;i++)
74         {
75             if((i+1)%2==0)
76             {
77                 printf("%c",n0[p0]);
78                 p0++;
79             }
80             else
81             {
82                 printf("%c",n1[p1]);
83                 p1++;
84             }
85         }
86         printf("\n");
87     }
88     return 0;
89 }

转载于:https://www.cnblogs.com/terryX/archive/2013/02/20/2918945.html

UVA10785 The Mad Numerologist相关推荐

  1. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  2. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  3. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  4. Best of Ruby Quiz 笔记之一:Mad Libs

    我想读<Best of Ruby Quiz>并实践里面的内容是熟悉ruby的一个好方法,那么让我从今天开始,每天都用ruby来quiz一下.             几点说明:1.我是ru ...

  5. python使用statsmodels包中的robust.mad函数以及pandas的apply函数计算dataframe中所有数据列的中位数绝对偏差(MAD)

    python使用statsmodels包中的robust.mad函数以及pandas的apply函数计算dataframe中所有数据列的中位数绝对偏差(MAD.Median Absolute Devi ...

  6. R语言dplyr包获取dataframe分组聚合汇总统计值实战(group_by() and summarize() ):均值、中位数、分位数、IQR、MAD、count、unique

    R语言dplyr包获取dataframe分组聚合汇总统计值实战(group_by() and summarize() ):均值.中位数.分位数.IQR.MAD.count.unique 目录

  7. 机器学习数据预处理之离群值/异常值:MAD法(绝对值差中位数法)+绝对中位差(Median Absolute Deviation,MAD)

    机器学习数据预处理之离群值/异常值:MAD法(绝对值差中位数法)+绝对中位差(Median Absolute Deviation,MAD) garbage in,garbage out. 异常值是分析 ...

  8. 机器学习数据清洗之异常数据处理、标准差法、MAD法、箱图法、图像对比法、异常值处理准则

    机器学习数据清洗之异常数据处理.标准差法.MAD法.箱图法.图像对比法.异常值处理准则 目录

  9. 【教程】新手如何制作简单MAD和AMV,学不会那都是时辰

    [教程]新手如何制作简单MAD和AMV,学不会那都是时 http://tieba.baidu.com/p/2303522172 [菜鸟教你做MAD]Vegas制作MAD入门教程 http://tieb ...

最新文章

  1. 如何在空硬盘Linux系统,Linux系统如何新增一块硬盘
  2. win10安装程序无法将配置为在此计算机,Win10安装会遇到的问题汇总及解决方法...
  3. 谷歌AutoML鼻祖Quoc Le新作AutoML-Zero:从零开始构建机器学习算法
  4. 《Sibelius 脚本程序设计》连载(三十四) - 4.4 DateTime
  5. JAVA16版本.JDK16即将发布,你准备好了吗?
  6. 偶搜集到的源码列表如下,跟大家分享分享。
  7. QTextEdit 不允许输入文字
  8. 190328文件处理
  9. 学习之路十四:客户端调用WCF服务的几种方法小议
  10. MySQL数据恢复--binlog
  11. html批量生成断面,【干货】利用Excel在AutoCAD中批量绘制断面图的方法
  12. foxmail 设置签名和信纸
  13. 音乐流媒体服务器Gonic
  14. 八代及以上笔记本发热降频的一般处理办法
  15. 小程的第一节C语言课
  16. 一维数组的使用:逆序输出数据/:任意输入5个数据,存放于数组,编程实现将这5个数据逆序存放并输出
  17. C语言中的常用循环语句
  18. 色卡矩形检测和颜色提取
  19. 【linux】【jenkins】自动化运维三 整合gitlab、docker发布vue项目
  20. 外卖餐饮管理系统开发源码

热门文章

  1. javascript基本功
  2. JavaScriptBreak 语句 continue 语句
  3. myeclipse2014删除antlr-2.7.2.jar--解决struts和hibernate包冲突
  4. 【英语天天读】I want I do I get
  5. 在WORD中插入带圈的数字的序号
  6. Linux C 读取文件夹下所有文件(包括子文件夹)的文件名
  7. 电视百科常识 九大视频接口全接触
  8. 明晰C++内存分配的五种方法的区别
  9. 【数字信号处理】——Python频谱绘制
  10. ANSYS——ANSYS后处理操作技巧与各类问题良心大总结