Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Put your name here
- * @date Put the date here
- * @file h07.cpp
- */
- #include <string>
- #include <iostream>
- using namespace std;
- string STUDENT = "vdinh29"; // Add your Canvas/occ-email ID
- #include "h07.h"
- // Place your function definitions in this file.
- string zipZap(const string& str)
- {
- string result;
- size_t i = 0, len = str.size(); // 1.
- if (len < 3) // 2.
- {
- return str;
- }
- while (i < len - 2) // 3.
- {
- string word = str.substr(i, 3); // 4.
- if (word.at(0) == 'z' && word.at(2) == 'p') // 5.
- {
- result += "zp";
- i += 3;
- }
- else // 6.
- {
- result += word.at(0);
- i++;
- }
- }
- result += str.substr(i); // 7.
- return result;
- }
- int countCode(const string& str)
- {
- int result = 0;
- for (size_t i = 0, len = str.size(); len > 3 && i < len - 3; ++i)
- {
- string code = str.substr(i, 4); // 1.
- string co = code.substr(0, 2); // 2.
- string e = code.substr(3);
- if (co == "co" && e == "e") // 3.
- {
- result ++;
- }
- }
- return result;
- }
- string everyNth(const string& str, int n)
- {
- string result;
- for (size_t i = 0, len = str.size(); i < len; i = i + n)
- {
- result += str.at(i);
- if (n < 1)
- {
- return result;
- }
- }
- return result;
- }
- bool prefixAgain(const string& str, int n)
- {
- bool result = false;
- string prefix = str.substr(0, n);
- for (size_t i = 1, len = str.size(); i < len; ++i)
- {
- string word = str.substr(i,n);
- if (word == prefix)
- {
- return true;
- }
- }
- return result;
- }
- ////////////////// STUDENT TESTING /////////////
- int run()
- {
- cout << "Student testing" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement