UVa 10785 - The Mad Numerologist

本文探讨了在C++环境下通过特定算法将字符按照元音和辅音进行分类,并实现相应的输出过程,包括读取输入、设置输出字符串以及生成案例。此程序展示了字符处理、数组操作和排序的基本技巧。

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

#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
char letter[2][22] = {"AUEOI", "JSBKTCLDMVNWFXGPYHQZR"};
int c[2] = {21, 5};
char t[22];
char out[212];
int n;

// k=0 vowel, k=1 consonant
// cnt 个数
void set_out(int k, int cnt)
{
    int times = c[k]; //单个字母出现最多次数
    int num, last;
    if(cnt%times) {
        num = cnt/times + 1;
        last = cnt%times;
    } else {
        num = cnt/times;
        last = times;
    }
    memcpy(t, letter[k], sizeof(t[0])*num);
    sort(t, t+num);
    for(int i=0, j=k; i<num; i++) {
        int l = t[i]==letter[k][num-1] ? last : times;
        while(l--) {
            out[j] = t[i];
            j += 2;
        }
    }
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    int T;
    scanf("%d", &T);
    for(int t=1; t<=T; t++) {
        scanf("%d", &n);
        set_out(0, n%2?n/2+1:n/2);
        set_out(1, n/2);
        out[n] = 0;
        printf("Case %d: %s\n", t, out);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值