Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- char mytoLower(char myString)
- {
- if ((myString >= 'A') && (myString <= 'Z'))
- {
- return myString - 'A' + 'a';
- }
- else
- {
- return myString;
- }
- }
- int strLen(const char*myString)
- {
- if (!*myString)
- {
- return 0;
- }
- return 1 + strLen(myString + 1);
- }
- int timesFound(const char*myString, const char*what, int stringLength, int whatLength)
- {
- int result = 0;
- int checker = 0;
- int i = 0;
- int k = 0;
- for (; i < stringLength; i++)
- {
- for (; k < whatLength; )
- {
- if (checker == whatLength)
- {
- result++;
- checker = 0;
- k = 0;
- break;
- }
- if (mytoLower(myString[i]) ==mytoLower(what[k]))
- {
- k++;
- checker++;
- if (checker == whatLength)
- {
- result++;
- checker = 0;
- k = 0;
- break;
- }
- break;
- }
- else
- {
- checker = 0;
- k = 0;
- break;
- }
- }
- }
- return result;
- }
- int main()
- {
- const int MAX_SIZE = 1024;
- int withSize, whatSize, stringSize,newStringLength;
- char*string = new(nothrow) char[MAX_SIZE];
- if (!string)
- {
- return 1;
- }
- cin.getline(string, MAX_SIZE);
- const char*myString = string;
- char*what = new(nothrow) char[MAX_SIZE];
- if (!what)
- {
- return 1;
- }
- cin.getline(what, MAX_SIZE);
- const char*myWhat = what;
- char*with = new(nothrow) char[MAX_SIZE];
- if (!with)
- {
- return 1;
- }
- cin.getline(with, MAX_SIZE);
- const char*myWith = with;
- withSize = strLen(myWith);
- whatSize = strLen(myWhat);
- stringSize = strLen(myString);
- newStringLength = stringSize + (withSize-whatSize)*timesFound(myString, what, stringSize, whatSize);
- cout << withSize<<" with\n";
- cout << whatSize << " what\n";
- cout << stringSize << " string\n";
- cout << newStringLength;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement