#include <iostream>#include <fstream>#include <string>#include <set>using namespace std;string shiftStringToLeft(const string &inStr) { string str = inStr; if (!str.empty()) { char c = str[0]; str = str.substr(1, str.size() - 1); str.push_back(c); } return str;}void numberOfDifferentPermutations(const string &inStr, set<string> &outArray) { int n = inStr.size(); string str = inStr; for (int i = 0; i < n; ++i) { outArray.insert(str); str = shiftStringToLeft(str); }}int amountOfSubstrings(string inStr, string substr) { int nfound = 0; size_t found = inStr.find(substr); while (found != string::npos) { nfound++; found = inStr.find(substr, found+1); } return nfound;}int nCyclicalSubstrings(string inStr, string substr) { set<string> outArray; numberOfDifferentPermutations(substr, outArray); set<string>::const_iterator it = outArray.begin(); int nfound = 0; int size = outArray.size(); for (int i = 0; i < size; ++i) { nfound += amountOfSubstrings(inStr, *it); it++; } return nfound;}int main(int argc, char** argv) { string inFileName = "input.txt"; ifstream in; in.open(inFileName.c_str()); if (!in.is_open()) { cerr << "Error: could not open the file " << inFileName.c_str() << endl; return 1; } string outFileName = "output.txt"; ofstream out; out.open(outFileName.c_str()); if (!out.is_open()) { cerr << "Error: could not open the file " << outFileName.c_str() << endl; in.close(); return 1; } string str; string substr; if (in >> str >> substr) { int result = nCyclicalSubstrings(str, substr); out << result << endl; } else { cerr << "Error: incorrect data in the file " << inFileName.c_str() << endl; in.close(); out.close(); return 1; } in.close(); out.close(); return 0;}
#include <fstream>#include <conio.h>#include <iostream>using namespace std;int main(int argc, char *argv[]){ ifstream input("input.txt"); if (!input) { exit(1); } string source ; std::getline(input, source); string findString; std::getline(input, findString); input.close(); if (findString.size() > source.size()) { exit(1); } string recursiveString = findString; int result = 0; for (int i = 0;i != findString.size(); i++) { recursiveString.insert(0, 1, recursiveString[recursiveString.size()-1]); recursiveString.erase(recursiveString.size()-1, 1); int pos = -recursiveString.size(); while(true) { pos = source.find(recursiveString, pos+recursiveString.size()); if (pos!= -1) result++; else break; } } ofstream out("OUTPUT.txt"); if (out) { out << result; } exit(0);}