All the Vowels Please

标题: All the Vowels Please

B. All the Vowels Please
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

题目大意:要求给出的一个k,存在n*m=k;并且在每行每列五个元音字母同时出现:

这个关键在于,找出5*5满足这个条件,当5 * 5满足数每一列就复制第一例中的字母,每一行就复制第一行的字母;
代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int n;
char str[205][2005];
int x, y;
int flag;
int main() {
	scanf("%d", &n);
	if (n < 25) {
		printf("-1\n");
		return 0;
	}
	for (int i = 5; i <= sqrt(n); i++) {
		if (n % i == 0) {
			x = i;
			y = n / i;
			flag = 1;
			break;
		}
	}
	if (!flag) {
			printf("-1\n");
			return 0;
		}
	char str6[6][6] = { {" "}, {" aeiou"} ,{" eioua"}, {" iouae"},{" ouaei"}, {" uaeio"} };
	if (n == 25) {
		printf("aeioueiouaiouaeouaeiuaeio");
		return 0;
	}
	for (int i = 1; i <= 5; i++) {
		for (int j = 1; j <= 5; j++) {
			str[i][j] = str6[i][j];
		}
	}
	for (int i = 1; i <= 5; i++) {
		for (int j = 6; j <= y; j++) {
			str[i][j] = str[i][1];
		}
	}
	for (int i = 6; i <= x; i++) {
		for (int j = 1; j <= y; j++) {
			str[i][j] = str[1][j];
		}
	}
	for (int i = 1; i <= x; i++) {
		for (int j = 1; j <= y; j++) {
			printf("%c", str[i][j]);
		}
	}
	return 0;
}

1.首先判断这个n是否小于25;
若小于必不可能成立

if (n < 25) {
		printf("-1\n");
		return 0;
	}

2.判断这个n是否能被分解成2个都大于或等于五的数

for (int i = 5; i <= sqrt(n); i++) {
		if (n % i == 0) {
			x = i;
			y = n / i;
			flag = 1;
			break;
		}
	}
	if (!flag) {
			printf("-1\n");
			return 0;
		}

如果可以就是取最小的一个(为了方便省事)

char str6[6][6] = { {" "}, {" aeiou"} ,{" eioua"}, {" iouae"},{" ouaei"}, {" uaeio"} };
	if (n == 25) {
		printf("aeioueiouaiouaeouaeiuaeio");
		return 0;
	}
	for (int i = 1; i <= 5; i++) {
		for (int j = 1; j <= 5; j++) {
			str[i][j] = str6[i][j];
		}
	}

把这些元音的字母存入进去

for (int i = 1; i <= 5; i++) {
		for (int j = 6; j <= y; j++) {
			str[i][j] = str[i][1];
		}
	}

把5列以外的所有位置都存上每一行的第一个子母;

for (int i = 1; i <= x; i++) {
		for (int j = 1; j <= y; j++) {
			printf("%c", str[i][j]);
		}
	}

把超过5行的每一行都一第一行的字母打出出来;

继续补提拔:实在太菜

题意很简单:就是每两个数的gcd()不为1;
并且不存在a%b==0;

这个其实打个表就好了;
但是就是感觉怪怪的

从后往前数:

#include<iostream>
#include<string>
#include<cstring>

using namespace std;

int main() {
	
	int t;
	int cnt;
	cin >> t;
	while (t--) {
		int x;
		cnt = 0;
		cin >> x;
		for (int i = 4 * x; i >= 2; i -= 2) {
			cnt++;
			if (cnt == x) {
				cout << i << endl;
				break;
			}
			cout << i << " ";
		}
	}

	return 0;
}

每个数-2,这样就可以保证题目中的两个条件;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值