Advertisement
vencinachev

Zadacha3

Dec 16th, 2020
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3.  
  4. using namespace std;
  5.  
  6. string capitals(const string& text);
  7.  
  8. int main()
  9. {
  10.     string input;
  11.     cout << "Enter your text: ";
  12.     getline(cin, input);
  13.     cout << "Output: " << capitals(input) << endl;
  14.     return 0;
  15. }
  16.  
  17. string capitals(const string& text)
  18. {
  19.     int flag = false;
  20.     string temp = "";
  21.     for (int i = 0; i < text.length(); i++)
  22.     {
  23.         if (text[i] == '[')
  24.         {
  25.             flag = true;
  26.             continue;
  27.         }
  28.         else if (text[i] == ']')
  29.         {
  30.             flag = false;
  31.             continue;
  32.         }
  33.         if (flag)
  34.         {
  35.             temp += toupper(text[i]);
  36.         }
  37.         else
  38.         {
  39.             temp += text[i];
  40.         }
  41.     }
  42.     return temp;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement