Advertisement
Lavig

Другий семестр. Лабораторна робота №4 (Завдання 1)

Feb 22nd, 2025
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     SetConsoleOutputCP(1251);
  10.     SetConsoleCP(1251);
  11.     int start_count{}, end_count{}, inside{};
  12.     char temp{};
  13.     string text{}, result{};
  14.     int i{};
  15.     cout << "Введіть будь-який текст: " << endl;
  16.     getline(cin, text);
  17.     for (i = 0; i < text.size(); i++) {
  18.         if (text[i] == '<') {
  19.             start_count++;
  20.             temp = text[i];
  21.         }
  22.         else if (text[i] == '>') {
  23.             end_count++;
  24.             temp = text[i];
  25.         }
  26.     }
  27.         if (start_count != end_count || temp != '>') {
  28.             for (i = 0; i < text.size(); i++) {
  29.                 cout << text[i];
  30.             }
  31.             return 0;
  32.         }
  33.         for (i = 0; i < text.size(); i++) {
  34.             if (text[i] == '<') {
  35.                 inside = 1;
  36.             }
  37.             if (inside == 0) {
  38.                 result += text[i];
  39.             }
  40.             if (text[i] == '>') {
  41.                 inside = 0;
  42.             }
  43.         }
  44.     for (i = 0; i < result.size(); i++) {
  45.         cout << result[i];
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement