Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <string>
- #include <string.h>
- using namespace std;
- #define pb push_back
- #define mp make_pair
- const string correctStart = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_йцукенгшщзхъфывапролджэячсмитьбюёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮЁ";
- const string correctSymb = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_йцукенгшщзхъфывапролджэячсмитьбюёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮЁ1234567890";
- bool checkFirstSymb(string s) {
- for (int i = 0; i < correctStart.size(); i++)
- if (s[0] == correctStart[i])
- return true;
- return false;
- }
- bool checkFullString(string s) {
- for (int i = 1; i < s.size(); i++) {
- bool isCorrect = false;
- for (int j = 0; j < correctSymb.size() && !isCorrect; j++)
- if (s[i] == correctSymb[j])
- isCorrect = true;
- if (!isCorrect)
- return false;
- }
- return true;
- }
- void printAns(vector<string> a, set<string> b) {
- cout << "Found all correct substrings: \n";
- for (int i = 0; i < a.size(); i++)
- cout << a[i] << ' ';
- cout << "\nFound unique correct substrings: \n";
- set<string> ::iterator it;
- for (it = b.begin(); it != b.end(); ++it)
- cout << *it << " ";
- }
- pair<vector<string>, set<string>> findSubstrings(string s) {
- vector<string> ansFull;
- set<string> ansUnique;
- bool isFind = false;
- string toPush;
- for (int i = 0; i < s.size(); i++) {
- isFind = false;
- for (int j = 0; j < correctStart.size(); j++)
- if (s[i] == correctStart[j]) {
- isFind = true;
- toPush = "";
- for (int c = i; c < s.size() && isFind; c++) {
- isFind = false;
- for (int k = 0; k < correctSymb.size() && !isFind; k++)
- if (s[c] == correctSymb[k])
- isFind = true;
- if (isFind) {
- toPush += s[c];
- ansFull.pb(toPush);
- if (ansUnique.find(toPush) == ansUnique.end())
- ansUnique.insert(toPush);
- }
- }
- }
- }
- return mp(ansFull, ansUnique);
- }
- int main(int argc, char* argv[]) {
- setlocale(LC_ALL, "Russian");
- string input, toPush;
- cout << "Enter your string:\n";
- getline(cin, input);
- cout << "The result of checking the correctness of the entered string: ";
- if (checkFirstSymb(input))
- if (checkFullString(input))
- cout << "True\n";
- else
- cout << "False\n";
- else
- cout << "False\n";
- pair<vector<string>, set<string>> ans = findSubstrings(input);
- printAns(ans.first, ans.second);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement