Codeforces #561 B.All the Vowels Please

Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length k is vowelly if there are positive integers n and m such that n⋅m=k and when the word is written by using n rows and m columns (the first row is filled first, then the second and so on, with each row filled from left to right), every vowel of the English alphabet appears at least once in every row and every column.

You are given an integer k and you must either print a vowelly word of length k or print −1 if no such word exists.

In this problem the vowels of the English alphabet are ‘a’, ‘e’, ‘i’, ‘o’ ,‘u’.

Input
Input consists of a single line containing the integer k (1≤k≤104) — the required length.

Output
The output must consist of a single line, consisting of a vowelly word of length k consisting of lowercase English letters if it exists or −1 if it does not.

If there are multiple possible words, you may output any of them.

Examples
inputCopy
7
outputCopy
-1
inputCopy
36
outputCopy
agoeuioaeiruuimaeoieauoweouoiaouimae
Note
In the second example, the word “agoeuioaeiruuimaeoieauoweouoiaouimae” can be arranged into the following 6×6 grid:
在这里插入图片描述
It is easy to verify that every row and every column contain all the vowels.
题解:
第一行:aeiou循环
第二行:eioua循环
第三行:iouae循环
第四行:ouaei循环
第五行:uaeio循环

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
#define dd double
using namespace std;

ll flag = 0;
ll x, y;

void sushu(ll q) {
	for (ll i = 2; i <= sqrt(q); i++) {
		if (q % i == 0) {
			if (i < 5 || (q / i) < 5) {
				continue;
			}
			x = i;
			y = (q / i);
			flag = 1;
			break;
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	string s1 = { 'a','e','i','o','u' };
	string s2 = { 'e','i','o','u','a' };
	string s3 = { 'i','o','u','a','e' };
	string s4 = { 'o','u','a','e','i' };
	string s5 = { 'u','a','e','i','o' };
	if (n < 25) {
		cout << "-1" << endl;
		return 0;
	}
	ll z;
	sushu(n);
	if (flag == 0) {
		cout << "-1" << endl;
	}
	else {
		for (ll i = 0; i < x; i++) {
			z = i % 5;
			if (z == 0) {
				for (ll j = 0; j < y; j++) {
					cout << s1[j % 5];
				}
			}
			if (z == 1) {
				for (ll j = 0; j < y; j++) {
					cout << s2[j % 5];
				}
			}
			if (z == 2) {
				for (ll j = 0; j < y; j++) {
					cout << s3[j % 5];
				}
			}
			if (z == 3) {
				for (ll j = 0; j < y; j++) {
					cout << s4[j % 5];
				}
			}
			if (z == 4) {
				for (ll j = 0; j < y; j++) {
					cout << s5[j % 5];
				}
			}
		}
		cout << endl;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值