Advertisement
tumaryui

Untitled

Mar 10th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <bits/stdc++.h>
  6.  
  7. using namespace std;
  8. bool car(string c, string z) {
  9. return c.size() > z.size();
  10. }
  11.  
  12.  
  13. int main()
  14. {
  15. setlocale(LC_ALL, "");
  16. int n;
  17. char y;
  18. cout << "Введите количество фраз" << endl;
  19. cin >> n;
  20. string m;
  21. string a[n];
  22. vector <string> vac;
  23. getchar();
  24. cout << "Введите фразу" << endl;
  25. for(int i = 0 ; i < n; i++) {
  26. getline(cin, a[i]);}
  27.  
  28. cout << "Введите слово" << endl;
  29. cin >> m ;
  30. for(int i = 0 ; i < n; i++) {
  31. if(a[i].find(m) != string::npos) {
  32. vac.push_back(a[i]);
  33. a[i]="-1";
  34. }
  35. }
  36.  
  37.  
  38. cout << "Выберите тип сортировки: 1) По длине фразе 2) По алфавиту " << endl;
  39. cin >> y;
  40. if (y == '1') {
  41. sort(a, a + n, car);
  42.  
  43. for(int i = 0; i < n; i++)
  44. if(a[i] != "-1" ) cout << a[i] << "\n";
  45. }
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement