kxcoze

lab22_12_2

Sep 9th, 2020 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3.  
  4. using namespace std;  
  5.  
  6. int main() {
  7.     SetConsoleCP(1251);
  8.     SetConsoleOutputCP(1251);
  9.    
  10.     char istream[1000];
  11.     int cnt = 0, ind = 0, maxCnt = 0, maxInd;
  12.     bool flag = false;
  13.    
  14.     cout << "Введите слова разделенные пробелами для преобразования:\n";
  15.     gets_s(istream);
  16.  
  17.     for (int i = 0; i < strlen(istream); i++) {
  18.         cnt++;
  19.  
  20.         if (maxCnt < cnt) {
  21.             maxCnt = cnt;
  22.             maxInd = ind;
  23.         }
  24.        
  25.         if (istream[i] == ' ') {
  26.             cnt = 0;
  27.             flag = true;
  28.         }
  29.         else if (flag) {
  30.             ind = i;
  31.             flag = false;
  32.         }  
  33.     }
  34.  
  35.     cout << "Самое длинное слово из текста: ";
  36.     for (int i = maxInd; i < strlen(istream) && istream[i] != ' '; i++) {
  37.         cout << istream[i];
  38.     }
  39.     cout << endl;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment