Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- char istream[1000];
- int cnt = 0, ind = 0, maxCnt = 0, maxInd;
- bool flag = false;
- cout << "Введите слова разделенные пробелами для преобразования:\n";
- gets_s(istream);
- for (int i = 0; i < strlen(istream); i++) {
- cnt++;
- if (maxCnt < cnt) {
- maxCnt = cnt;
- maxInd = ind;
- }
- if (istream[i] == ' ') {
- cnt = 0;
- flag = true;
- }
- else if (flag) {
- ind = i;
- flag = false;
- }
- }
- cout << "Самое длинное слово из текста: ";
- for (int i = maxInd; i < strlen(istream) && istream[i] != ' '; i++) {
- cout << istream[i];
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment