题目链接:https://codeforces.com/contest/1166/problem/B
B. All the Vowels Please
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length kk is vowelly if there are positive integers nn and mm such that n⋅m=kn⋅m=k and when the word is written by using nn rows and mm 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 kk and you must either print a vowelly word of length kk or print −1−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 kk (1≤k≤1041≤k≤104) — the required length.
Output
The output must consist of a single line, consisting of a vowelly word of length kk consisting of lowercase English letters if it exists or −1−1 if it does not.
If there are multiple possible words, you may output any of them.
Examples
input
Copy
7
output
Copy
-1
input
Copy
36
output
Copy
agoeuioaeiruuimaeoieauoweouoiaouimae
Note
In the second example, the word "agoeuioaeiruuimaeoieauoweouoiaouimae" can be arranged into the following 6×66×6 grid:
It is easy to verify that every row and every column contain all the vowels.
思路:最最重要的,找出5*5的图表,之后就按顺序循环输出即可。
a | e | i | o | u | a |
e | i | o | u | a | e |
i | o | u | a | e | i |
o | u | a | e | i | o |
u | a | e | i | o | u |
a | e | i | o | u | a |
代码:
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main()
{
int fla = 0;
int m, n;
int k;
cin >> k;
for (int i = 5; i <= sqrt(k); i++)
{
if (k%i == 0)
{
m = i;
n = k / i;
fla = 1;
break;
}
}
if (fla == 0)cout << -1;
else
{
for (int i = 1; i <= m; i++)
{
if (i % 5 == 1)
{
for (int j = 1; j <= n; j++)
{
if (j % 5 == 1)cout << "a";
if (j % 5 == 2)cout << "e";
if (j % 5 == 3)cout << "i";
if (j % 5 == 4)cout << "o";
if (j % 5 == 0)cout << "u";
}
}
if (i % 5 == 2)
{
for (int j = 1; j <= n; j++)
{
if (j % 5 == 1)cout << "e";
if (j % 5 == 2)cout << "i";
if (j % 5 == 3)cout << "o";
if (j % 5 == 4)cout << "u";
if (j % 5 == 0)cout << "a";
}
}
if (i % 5 == 3)
{
for (int j = 1; j <= n; j++)
{
if (j % 5 == 1)cout << "i";
if (j % 5 == 2)cout << "o";
if (j % 5 == 3)cout << "u";
if (j % 5 == 4)cout << "a";
if (j % 5 == 0)cout << "e";
}
}
if (i % 5 == 4)
{
for (int j = 1; j <= n; j++)
{
if (j % 5 == 1)cout << "o";
if (j % 5 == 2)cout << "u";
if (j % 5 == 3)cout << "a";
if (j % 5 == 4)cout << "e";
if (j % 5 == 0)cout << "i";
}
}
if (i % 5 == 0)
{
for (int j = 1; j <= n; j++)
{
if (j % 5 == 1)cout << "u";
if (j % 5 == 2)cout << "a";
if (j % 5 == 3)cout << "e";
if (j % 5 == 4)cout << "i";
if (j % 5 == 0)cout << "o";
}
}
}
}
}