Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. /**
  2. * @author Put your name here
  3. * @date Put the date here
  4. * @file h07.cpp
  5. */
  6. #include <string>
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. string STUDENT = "vdinh29"; // Add your Canvas/occ-email ID
  11.  
  12. #include "h07.h"
  13.  
  14. // Place your function definitions in this file.
  15. string zipZap(const string& str)
  16. {
  17. string result;
  18. size_t i = 0, len = str.size(); // 1.
  19. if (len < 3) // 2.
  20. {
  21. return str;
  22. }
  23. while (i < len - 2) // 3.
  24. {
  25. string word = str.substr(i, 3); // 4.
  26. if (word.at(0) == 'z' && word.at(2) == 'p') // 5.
  27. {
  28. result += "zp";
  29. i += 3;
  30. }
  31. else // 6.
  32. {
  33. result += word.at(0);
  34. i++;
  35. }
  36. }
  37. result += str.substr(i); // 7.
  38. return result;
  39. }
  40.  
  41.  
  42. int countCode(const string& str)
  43. {
  44. int result = 0;
  45. for (size_t i = 0, len = str.size(); len > 3 && i < len - 3; ++i)
  46. {
  47. string code = str.substr(i, 4); // 1.
  48. string co = code.substr(0, 2); // 2.
  49. string e = code.substr(3);
  50. if (co == "co" && e == "e") // 3.
  51. {
  52. result ++;
  53. }
  54. }
  55. return result;
  56. }
  57. string everyNth(const string& str, int n)
  58. {
  59. string result;
  60. for (size_t i = 0, len = str.size(); i < len; i = i + n)
  61. {
  62. result += str.at(i);
  63.  
  64. if (n < 1)
  65. {
  66. return result;
  67. }
  68. }
  69. return result;
  70. }
  71. bool prefixAgain(const string& str, int n)
  72. {
  73. bool result = false;
  74. string prefix = str.substr(0, n);
  75. for (size_t i = 1, len = str.size(); i < len; ++i)
  76. {
  77. string word = str.substr(i,n);
  78. if (word == prefix)
  79. {
  80. return true;
  81. }
  82. }
  83. return result;
  84. }
  85.  
  86.  
  87.  
  88.  
  89. ////////////////// STUDENT TESTING /////////////
  90. int run()
  91. {
  92. cout << "Student testing" << endl;
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement