日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

All the Vowels Please

發布時間:2023/12/9 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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,這樣就可以保證題目中的兩個條件;

總結

以上是生活随笔為你收集整理的All the Vowels Please的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。