Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <stdio.h>
  4. #include <string>
  5. #include <cstring>
  6. #include <vector>
  7. using namespace std;
  8. void proc1(vector<string> str, vector<string> &subs) {
  9. bool check = false;
  10. int j = 0, t = 0;
  11. for (int i = 0; i<str.size(); i++) {
  12. j = 0;
  13. while (j < str.at(i).size()-1) {
  14. check = false;
  15. if (str.at(i).at(j) != '>' && str.at(i).at(j) != '<' && str.at(i).at(j) != '=') {
  16. t = j;
  17. while (t < str.at(i).size() && !check) {
  18. if (str.at(i).at(t) == '>' || str.at(i).at(t) == '<' || str.at(i).at(t) == '=') {
  19. subs.push_back(str.at(i).substr(j, t-j));
  20. check = true;
  21. j = t;
  22. }
  23. else if (t == str.at(i).size() - 1) {
  24. subs.push_back(str.at(i).substr(j, t-j+1));
  25. check = true;
  26. j = t;
  27. }
  28. else
  29. t++;
  30. }
  31. }
  32. else
  33. j++;
  34. }
  35. }
  36. }
  37. void proc2(vector<string> subs, string &sub0){
  38. int k, max=0, nmax=-1;
  39. sub0="";
  40. for (int i=0;i<subs.size();i++){
  41. k=0;
  42. for (int j=0;j<subs.at(i).size();j++){
  43. if (subs.at(i).at(j)>='a' && subs.at(i).at(j)<='z')
  44. k++;
  45. }
  46. if (k>max){
  47. nmax=i;
  48. max=k;
  49. }
  50. }
  51. if (nmax!=-1)
  52. sub0=subs.at(nmax);
  53. }
  54. void proc3(string &s0){
  55. string engb="QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
  56. int len=s0.size(), i=0;
  57. while (i<s0.size()){
  58. if (strchr(engb.c_str(),s0.at(i))==0){
  59. len--;
  60. for (int j=i;j<s0.size()-1;j++)
  61. s0.at(j)=s0.at(j+1);
  62. s0.resize(len);
  63. }
  64. else
  65. i++;
  66. }
  67. }
  68. int main() {
  69. string s, sub0, s0=""; vector<string> str, subs;
  70. bool check = false;
  71. int j = 0, t = 0, len0;
  72. setlocale(LC_ALL, "rus");
  73. cout << "Введите строки." << endl;
  74. do {
  75. getline(cin, s);
  76. if (s.size() == 0)
  77. check = true;
  78. else
  79. str.push_back(s);
  80. } while (!check);
  81. cout << "Задание №1.\n";
  82. proc1(str, subs);/*Задание №1*/
  83. if (subs.size()==0){
  84. cout << "Нет нужных подстрок.\n";
  85. exit(0);
  86. }else{
  87. cout << "Полученные подстроки:\n";
  88. for (int i = 0; i<subs.size(); i++)
  89. cout << i + 1 << ") " << subs.at(i) << endl;
  90. }
  91. cout << "\nЗадание №2.\n";
  92. proc2(subs, sub0);/*Задание №2*/
  93. if (sub0==""){
  94. cout << "Нет нужной подстроки.\n";
  95. exit(0);
  96. }
  97. else
  98. cout << "Полученная подстрока: " << sub0 << endl;
  99. cout << "\nЗадание №3.\n";
  100. for (int i=0;i<str.size() && s0=="";i++)
  101. if (strstr(str.at(i).c_str(),sub0.c_str())>0)
  102. s0=str.at(i);
  103. cout << "Исходная строка: " << s0 << endl;
  104. len0=s0.size();
  105. proc3(s0);/*Задание №3*/
  106. if (len0==s0.size())
  107. cout << "Строка не изменилась.\n";
  108. else if (s0.size()==0)
  109. cout << "Строка полностью удалена.\n";
  110. else
  111. cout << "Измененная строка : " << s0 << endl;
  112. system("pause");
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement