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滿足數每一列就復制第一例中的字母,每一行就復制第一行的字母;
代碼:
1.首先判斷這個n是否小于25;
若小于必不可能成立
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,這樣就可以保證題目中的兩個條件;
總結
以上是生活随笔為你收集整理的All the Vowels Please的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python抠图教程视频_3行Pytho
- 下一篇: mysql 删除5天前 备份_mysql