Advertisement
CLazStudio

q203735321

Oct 9th, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char* argv[]) {
  8.     string str;
  9.     size_t pos = 0;
  10.     cout << "2. Введите строку со словами 'word': " << endl;
  11.     getline(cin, str);
  12.     while ((pos = str.find("word", pos)) != string::npos) {
  13.         str.replace(pos, 4, "letter");
  14.         pos += 4;
  15.     }
  16.     cout << str << endl;
  17.  
  18.     int n = 0;
  19.     cout << "\n3. Введите количество строк в массиве: ";
  20.     cin >> n;
  21.     cin.ignore();
  22.     cout << "Введите " << n << " строк, каждую на новой строке: " << endl;
  23.     string *a = new string[n];
  24.     for (int i = 0; i < n; i++)
  25.         getline(cin, a[i]);
  26.     sort(a, a + n, [](const string &a, const string &b) -> bool
  27.     {
  28.         return a.length() > b.length();
  29.     });
  30.  
  31.     cout << "\nСтроки отсортированы по длине: " << endl;
  32.     for (int i = 0; i < n; i++)
  33.         cout << a[i] << endl;
  34.  
  35.     cin.get();
  36.     delete[] a;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement