UVA 10785 疯狂的命理学家

注意no more than 5, no more than 21 是小于而不是小于等于

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <map>
using namespace std;
///
#define INF 0xffffff7
#define MAXN 200 
///
int len;
int N;
char val[] = "12345678912345678912345678";
int used[26];
bool isNot(char a)
{
	if ( (a != 'A') && (a != 'E') && (a != 'I') && (a != 'O') && (a != 'U') )
		return true;
	else
		return false;
}
int main()
{
	///
	int i, j;
	cin >> N;
	int cases = 1;
	while (N--)
	{
		cin >> len;
		memset(used, 0, sizeof(used));
		string name1("");
		string name2("");
		for (i = 0; i < len; i++)
		{
			if (i % 2 == 0)
			{
				if (used['A' - 'A'] < 21)
				{
					name1 += 'A';
					used['A' - 'A']++;
				}
				else if (used['U' - 'A'] < 21)
				{
					name1 += 'U';
					used['U' - 'A']++;
				}
				else if (used['E' - 'A'] < 21)
				{
					name1 += 'E';
					used['E' - 'A']++;
				}
				else if (used['O' - 'A'] < 21)
				{
					name1 += 'O';
					used['O' - 'A']++;
				}
				else
				{
					name1 += 'I';
					used['I' - 'A']++;
				}
			}
			else
			{
				int v = INF;
				int pos;
				for (j = 0; j < 26; j++)
				{
					if (used[j] < 5 && isNot('A' + j))
					{
						if ( (val[j]) < v)
						{
							v = val[j];
							pos = j;
						}
					}
				}
				name2 += ('A' + pos);
				used[pos]++;
			}
		}
		sort(name1.begin(), name1.end());
		sort(name2.begin(), name2.end());
		i = 0;
		j = 0;
		int k = 0;
		string name("");
		while (k < len)
		{
			if (k % 2 == 0)
			{
				name += name1[i];
				i++;
				k++;
			}
			else
			{
				name += name2[j];
				j++;
				k++;
			}
		}
		cout << "Case " << cases << ": " << name << endl;
		cases++;
		
	}
	
    ///
    return 0;
	
}


 转载一个霸道的解法

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
const string kStr("AJAJAJAJAJASASASASASABABABABABAKAKAKAKAKATUTUTUTUTUCUCUCUCUCULULULULULUDUDUDUDUDUMUMEMEMEMEVEVEVEVEVENENENENENEWEWEWEWEWEFEFEFOFOFOXOXOXOXOXOGOGOGOGOGOPOPOPOPOPOYOYOYOYIYIHIHIHIHIHIQIQIQIQIQIZIZIZIZIZIRIRIRIRIR");

int main()
{
    int T;
    cin>>T;
    for(int case_num=1;case_num<=T;case_num++)
    {
        int n;
        cin>>n;

        string ans(kStr.substr(0,n));
        string odd,even;
        for(int i=0;i<n;i+=2)
            odd+=ans[i];
        for(int i=1;i<n;i+=2)
            even+=ans[i];
        sort(odd.begin(),odd.end());
        sort(even.begin(),even.end());

        cout<<"Case "<<case_num<<": ";
        for(int i=0;i<n;i++)
            if(i&1)
                cout<<even[i>>1];
            else
                cout<<odd[i>>1];
        cout<<endl;
    }

    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值