The Mad Numerologist UVA

本文详细介绍了如何通过简单的数学运算,为个人命名提供幸运的建议,涉及占星术中字母的数值分配及组合,强调了在保持发音流畅的前提下,通过优化元音和辅音的排列顺序,确保名字的字典序最小,从而达到增加幸运的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

3
1
5
5

Sample Output 

Case 1: A
Case 2: AJAJA
Case 3: AJAJA
此题较水,要注意最后的结果字典序要最小,所以要分别对名字的辅音元音进行排序。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char table[3][10];
char nameopp[300];
char nameeven[300];
int times[26];
void init()
{
    int s='A';
    for(int i=0;i<3;i++)
       for(int j=1;j<=9;j++)
       {
         table[i][j]=s++;
        // if(s>'Z') break;
       }
}
bool judge(char s)
{
    if(s=='A') return true;
    if(s=='E') return true;
    if(s=='I') return true;
    if(s=='O') return true;
    if(s=='U') return true;
    return false;
}
int main()
{
   init();
    int n,N,os=0,es=0,k=0;
    cin>>n;
    while(n--)
    {
        memset(times,0,sizeof(times));
        cin>>N;os=0;es=0;
        for(int i=0;i<N;i++)
        {
            for(int j=1;j<=9;j++)
               { bool out=true;
                   for(int k=0;k<3;k++)
                {
                  if(i%2==0&&judge(table[k][j])&×[table[k][j]-'A']<21&&table[k][j]<='Z')
                  {
                    nameopp[os++]=table[k][j];times[table[k][j]-'A']++;out=false;break;
                  }
                  if(i%2!=0&&!judge(table[k][j])&×[table[k][j]-'A']<5&&table[k][j]<='Z')
                  {
                       nameeven[es++]=table[k][j];times[table[k][j]-'A']++;out=false;break;
                       //cout<<table[k][j]<<times[table[k][j]-'A']<<endl;
                  }
                }
                if(!out) break;
               }
        }
        sort(nameopp,nameopp+os);
        sort(nameeven,nameeven+es);
        cout<<"Case "<<++k<<": ";
        int no=0,ne=0;
       for(int i=0;i<N;i++)
       {
           if(i%2==0) cout<<nameopp[no++];
           else cout<<nameeven[ne++];
       }
       cout<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值