Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <Windows.h>
- #include <iostream>
- #include <string>
- #include <ctime>
- using namespace std;
- int i, j;
- int main()
- {
- SetConsoleCtrlHandler(NULL, true);
- setlocale(LC_ALL, "russian");
- srand(time(NULL));
- cout << "Введите порядок (от 2 до 5) квадратной матрицы: ";
- string por;
- char por1 = 0;
- cin >> por;
- while (por.length() != 1) {
- cin.clear();
- cout << "Ошибка. Введите число от 2 до 5: ";
- cin >> por;
- }
- por1 = por[0];
- while (por1 < '2' || por1 > '5') {
- cin.clear();
- cout << "Ошибка. Введите число от 2 до 5: ";
- cin >> por;
- por1 = por[0];
- }
- int p = int(por1) - 48;
- string **words = new string*[p];
- for (int i = 0; i < p; i++) {
- words[i] = new string[p];
- }
- cout << "Заполнить матрицу:" << endl << "1) Вручную" << endl << "2) Случайно" << endl << "-> ";
- string c2;
- char c1;
- cin >> c2;
- while (c2.length() != 1) {
- cout << "Ошибка. Введите 1 или 2: ";
- cin >> c2;
- cin.clear();
- }
- c1 = c2[0];
- while (c1 != '1' && c1 != '2') {
- por1 = por[0];
- cout << "Ошибка. Введите 1 или 2: ";
- cin >> por;
- }
- int c = int(c1) - 48;
- string word;
- switch (c) {
- case 1:
- int i, j, n;
- cout << "Введите " << p * p << " слов из четырёх букв английского алфавита" << endl;
- char ch;
- bool check;
- for (i = 0; i < p; i++) {
- for (j = 0; j < p; j++) {
- check = false;
- cout << endl << "Введите элемент: ";
- while (check == false) {
- cin >> word;
- while (word.length() != 4) {
- cout << "Неверная длина слова. Введите слово из 4-х букв: ";
- cin >> word;
- }
- for (int n = 0; n < 4; n++) {
- ch = word[n];
- if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
- check = true;
- else {
- check = false;
- cout << "Слово должно состоять только из букв английского алфавита. Ввведите новое: ";
- break;
- }
- }
- }
- cout << "Принято";
- words[i][j] = word;
- }
- }
- break;
- case 2:
- string word(4, 0);
- int tmp = 0;
- for (int i = 0; i < p; i++)
- for (int j = 0; j < p; j++) {
- for (int n = 0; n < 4; n++) {
- while (tmp < 97 || tmp>122)
- tmp = rand() % 205 + 50;
- word[n] = tmp;
- tmp = 0;
- }
- words[i][j] = word;
- }
- cout << endl << "Сгенерированный массив:";
- for (i = 0; i < p; i++) {
- cout << endl << endl;
- for (j = 0; j < p; j++)
- cout << words[i][j] << "\t";
- }
- }
- char ch;
- for (i = 0; i < p; i++) {
- for (j = 0; j < p; j++) {
- word = words[i][j];
- int n = 0;
- char ch = '0';
- while (n < word.length()) {
- ch = word[n]; //A E I O U Y
- n++;
- if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'Y' || ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y') {
- n--;
- word.erase(n, 1);
- }
- }
- if (word.length() == 0)
- word = "*";
- words[i][j] = word;
- }
- }
- cout << endl << endl << "Обработанный массив:";
- for (i = 0; i < p; i++) {
- cout << endl << endl;
- for (j = 0; j < p; j++)
- cout << words[i][j] << "\t";
- }
- int *leng = new int[p*p];
- cout << endl << endl;
- int n = 0;
- for (i = 0; i < p; i++) {
- for (j = 0; j < p; j++) {
- word = words[i][j];
- if (word.find('*') != -1)
- leng[n] = 0;
- else
- leng[n] = word.length();
- n++;
- }
- }
- int temp;
- for (int i = 0; i < p*p - 1; i++) {
- for (int j = 0; j < p*p - i - 1; j++) {
- if (leng[j] < leng[j + 1]) {
- temp = leng[j];
- leng[j] = leng[j + 1];
- leng[j + 1] = temp;
- }
- }
- }
- cout << endl << "Массив из размеров строк матрицы:" << endl;
- for (int n = 0; n < p*p; n++)
- cout << leng[n] << " ";
- cout << endl;
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement