Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <stdio.h>
- #include <string>
- #include <cstring>
- #include <vector>
- using namespace std;
- void proc1(vector<string> str, vector<string> &subs) {
- bool check = false;
- int j = 0, t = 0;
- for (int i = 0; i<str.size(); i++) {
- j = 0;
- while (j < str.at(i).size()-1) {
- check = false;
- if (str.at(i).at(j) != '>' && str.at(i).at(j) != '<' && str.at(i).at(j) != '=') {
- t = j;
- while (t < str.at(i).size() && !check) {
- if (str.at(i).at(t) == '>' || str.at(i).at(t) == '<' || str.at(i).at(t) == '=') {
- subs.push_back(str.at(i).substr(j, t-j));
- check = true;
- j = t;
- }
- else if (t == str.at(i).size() - 1) {
- subs.push_back(str.at(i).substr(j, t-j+1));
- check = true;
- j = t;
- }
- else
- t++;
- }
- }
- else
- j++;
- }
- }
- }
- void proc2(vector<string> subs, string &sub0){
- int k, max=0, nmax=-1;
- sub0="";
- for (int i=0;i<subs.size();i++){
- k=0;
- for (int j=0;j<subs.at(i).size();j++){
- if (subs.at(i).at(j)>='a' && subs.at(i).at(j)<='z')
- k++;
- }
- if (k>max){
- nmax=i;
- max=k;
- }
- }
- if (nmax!=-1)
- sub0=subs.at(nmax);
- }
- void proc3(string &s0){
- string engb="QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
- int len=s0.size(), i=0;
- while (i<s0.size()){
- if (strchr(engb.c_str(),s0.at(i))==0){
- len--;
- for (int j=i;j<s0.size()-1;j++)
- s0.at(j)=s0.at(j+1);
- s0.resize(len);
- }
- else
- i++;
- }
- }
- int main() {
- string s, sub0, s0=""; vector<string> str, subs;
- bool check = false;
- int j = 0, t = 0, len0;
- setlocale(LC_ALL, "rus");
- cout << "Введите строки." << endl;
- do {
- getline(cin, s);
- if (s.size() == 0)
- check = true;
- else
- str.push_back(s);
- } while (!check);
- cout << "Задание №1.\n";
- proc1(str, subs);/*Задание №1*/
- if (subs.size()==0){
- cout << "Нет нужных подстрок.\n";
- exit(0);
- }else{
- cout << "Полученные подстроки:\n";
- for (int i = 0; i<subs.size(); i++)
- cout << i + 1 << ") " << subs.at(i) << endl;
- }
- cout << "\nЗадание №2.\n";
- proc2(subs, sub0);/*Задание №2*/
- if (sub0==""){
- cout << "Нет нужной подстроки.\n";
- exit(0);
- }
- else
- cout << "Полученная подстрока: " << sub0 << endl;
- cout << "\nЗадание №3.\n";
- for (int i=0;i<str.size() && s0=="";i++)
- if (strstr(str.at(i).c_str(),sub0.c_str())>0)
- s0=str.at(i);
- cout << "Исходная строка: " << s0 << endl;
- len0=s0.size();
- proc3(s0);/*Задание №3*/
- if (len0==s0.size())
- cout << "Строка не изменилась.\n";
- else if (s0.size()==0)
- cout << "Строка полностью удалена.\n";
- else
- cout << "Измененная строка : " << s0 << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement