Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- int main(int argc, char* argv[]) {
- string str;
- size_t pos = 0;
- cout << "2. Введите строку со словами 'word': " << endl;
- getline(cin, str);
- while ((pos = str.find("word", pos)) != string::npos) {
- str.replace(pos, 4, "letter");
- pos += 4;
- }
- cout << str << endl;
- int n = 0;
- cout << "\n3. Введите количество строк в массиве: ";
- cin >> n;
- cin.ignore();
- cout << "Введите " << n << " строк, каждую на новой строке: " << endl;
- string *a = new string[n];
- for (int i = 0; i < n; i++)
- getline(cin, a[i]);
- sort(a, a + n, [](const string &a, const string &b) -> bool
- {
- return a.length() > b.length();
- });
- cout << "\nСтроки отсортированы по длине: " << endl;
- for (int i = 0; i < n; i++)
- cout << a[i] << endl;
- cin.get();
- delete[] a;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement