Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <Windows.h>
- using namespace std;
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- cout << "Lab6" << endl;
- //Задание 1//
- /*cout << "Задание 1" << endl;
- string str;
- int count = 0;
- cout << "Введите предложение:\n";
- getline(cin, str);
- for (int i = 1; i <= str.length(); i++)
- if (str[i - 1] == 'а' && (str[i] == ' ' or str[i] == '\0'))
- count++;
- if (count > 0)
- cout << "Найдено слов: " << count << endl;
- else
- cout << "Нет таких слов" << endl;*/
- //Задание 2
- // cout << "Задание 2" << endl;
- // string str;
- //
- // cout << "Введите предложение:\n";
- // getline(cin, str);
- //
- // for (int i = 0; i < str.length(); i++)
- // if (str[i] == ' ')
- // {
- // if (i > 0)
- // if (str[i - 1] != ' ')
- // cout << endl;
- // }
- // else
- // cout << str[i];
- //Задание 3//
- //cout << "Задание 3" << endl;
- //string str;
- //string str_add = ".exe";
- //cout << "Введите имя файла:\n";
- //getline(cin, str);
- //for (int i = str.length(); i > 0; i--)
- //{
- // if (str[i] == ' ' and str[i-1] != ' ')
- // str.erase(i);
- // if (str[i] == '\\')
- // break;
- // if (str[i] == '.')
- // str.erase(i);
- //}
- //str.append(str_add);
- //cout << str;
- //Задание 4//
- /*cout << "Задание 4" << endl;
- string str;
- string name1;
- string name2;
- int number=0;
- cout << "Введите ФИО:\n";
- getline(cin, str);
- for (int i = 0; i < str.length(); i++)
- {
- if (str[i] == ' ')
- {
- if (i > 0)
- if (str[i - 1] != ' ')
- {
- number++;
- if (number == 2)
- break;
- }
- }
- else if (number)
- name1.push_back(str[i]);
- else
- name2.push_back(str[i]);
- }
- cout << "Результат\n" << "Привет, " << name1 << " " << name2 << endl;*/
- ////Задание 5//
- //cout << "Задание 5" << endl;
- //string str;
- //
- //string str_rep = "Юра";
- //string str_old = "Вася";
- //cout << "Введите предложение :\n";
- //getline(cin, str);
- //int pos = 0;
- //
- //while(-1!=(pos=str.find(str_old,pos)))
- // str.replace(pos, str_old.length(), str_rep);
- //cout << str;
- //Задание 6//
- cout << "Задание 6" << endl;
- string str;
- string str_rep = "Привет";
- string str_old;
- cout << "Введите предложение :\n";
- getline(cin, str);
- int pos=0;
- int sign = 0;
- for (int i = 0; i <= str.length(); i++)
- {
- if ((str[i] == '.') or (str[i] == ',') or (str[i] == '!') or (str[i] == '?'))
- {
- sign++;
- continue;
- }
- if (str[i] == ' ' or str[i] == '\0')
- {
- if (i > 0)
- if (str[i - 1] != ' ')
- {
- pos = str.find(str_old, pos);
- str.replace(pos, str_old.length(), str_rep);
- i = pos + str_rep.length()+sign;
- str_old = "";
- sign = 0;
- }
- }
- else
- str_old.push_back(str[i]);
- }
- cout << str;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement