Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdafx.h>
- #include <iostream>
- #include <Windows.h>
- #include <string.h>
- //задан текст, напечатать все слова в алфавитном порядке
- using namespace std;
- int main()
- {
- SetConsoleCP(1251);//Включение кодировки 1251 поддержживающей кирилицу
- SetConsoleOutputCP(1251);
- char Text[1000], b;//Массив текста и Буферная переменная для считывания текста
- char TextSlov[100][100]; //Матрица слов
- int j, Kolvo = 0;;//Счетчик и количество слов
- cout << "Enter text: ";
- for (j = 0; (b = cin.get()) != '\n'; j++) //Посимвольный ввод текста
- {
- Text[j] = b;
- if (b == ' ')
- Kolvo++; //Подсчет количества слов
- }
- Text[j] = '\0';
- Kolvo++;
- int Start = 0;//Поизиция начало слова
- int num = 0;//зануление счетчика
- cout << "Amount of words:" << Kolvo << endl;
- cout << "Text: " << Text << endl;
- for (int g = 0;; g++) //Цикл поиска слов
- {
- if (Text[g] == ' ' || Text[g] == '\0') //Условие промежутка между слов
- {
- int f;
- int u = 0;
- for (f = Start; f < g; f++) //Вывод если проверка прошла успешно
- {
- TextSlov[num][u] = Text[f];
- u++;
- }
- TextSlov[num][u] = '\0';
- Start = g + 1; //Переключение указателя на новое слово
- num++;
- }
- if (Text[g] == '\0') break;//Провека строки на конец
- }
- for (int i = 0; i < num - 1; i++)
- for (j = 0; j < num - i - 1; j++)
- {
- if (strcmp(TextSlov[j], TextSlov[j + 1]) > 0)
- {
- char swap[1][100];
- strcpy_s(swap[0], TextSlov[j]);
- strcpy_s(TextSlov[j], TextSlov[j + 1]);
- strcpy_s(TextSlov[j + 1], swap[0]);
- }
- }
- cout << "Sorted words: ";
- for (int g = 0; g < num; g++)
- {
- for (int h = 0; TextSlov[g][h] != '\0'; h++)
- cout << TextSlov[g][h];
- cout << " ";
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement