Problem p01145 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
bool is_one_of(char c, string const &s) { return s.find(c) != string::npos; }
bool is_vowel(char c) { return is_one_of(c, "aiueo"); }
bool is_voiceless_consonant(char c) { return is_one_of(c, "ksthp"); }
int main() {
  while (true) {
    string s;
    cin >> s;
    if (s == "#")
      break;
    s = string() + "^^^^" + s + "$$$$$$$$";
    string t;
    bool is_canceled = false;
    repeat(i, s.length()) {
      if (s[i] == '^' or s[i] == '$') {
        continue;
      }
      if (is_canceled and is_vowel(s[i])) {
        t += s[i];
        is_canceled = false;
        continue;
      }
      bool is_left_voiceless_consonant_y =
          is_voiceless_consonant(s[i - 1]) or
          (is_voiceless_consonant(s[i - 2]) and s[i - 1] == 'y');
      if (is_left_voiceless_consonant_y and is_one_of(s[i], "iu") and
          (s[i + 1] == '$' or is_voiceless_consonant(s[i + 1]))) { // rule 1
        t += string() + "(" + s[i] + ")";
        is_canceled = true;
        continue;
      }
      if (is_left_voiceless_consonant_y and is_one_of(s[i], "ao") and
          is_voiceless_consonant(s[i + 1])) {
        if (s[i + 2] == s[i] or
            (s[i + 2] == 'y' and s[i + 3] == s[i])) { // rule 2
          t += string() + "(" + s[i] + ")";
          is_canceled = true;
          continue;
        }
      }
      t += s[i];
    }
    cout << t << endl;
  }
  return 0;
}

Error: 0
kusa -> k(u)sa
haha -> h(a)ha
hakata -> h(a)kata
kippu -> k(i)ppu
sasakisan -> s(a)sak(i)san
sosonokasu -> s(o)sonokas(u)
hottokouhii -> hott(o)kouhii
i -> i


Fixed submission:

#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i, m, n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(f, x, ...)                                                       \\
  ([&](decltype((x)) whole) {                                                  \\
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \\
  })(x)
#define unittest_name_helper(counter) unittest_##counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__)()
using ll = long long;
using namespace std;
template <class T> inline void setmax(T &a, T const &b) { a = max(a, b); }
template <class T> inline void setmin(T &a, T const &b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) {
  return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
  auto cont = vectors(y, z, zs...);
  return vector<decltype(cont)>(x, cont);
}

bool is_one_of(char c, string const &s) { return s.find(c) != string::npos; }
bool is_vowel(char c) { return is_one_of(c, "aiueo"); }
bool is_consonant(char c) { return islower(c) and not is_vowel(c); }
bool is_voiceless_consonant(char c) { return is_one_of(c, "ksthp"); }

int main() {
  while (true) {
    string s;
    cin >> s;
    if (s == "#")
      break;
    cerr << s;
    s = string() + "^^^^" + s + "$$$$$$$$";
    string t;
    bool is_canceled = false;
    repeat(i, s.length()) {
      if (s[i] == '^' or s[i] == '$') {
        continue;
      }
      if (is_canceled and is_vowel(s[i])) {
        t += s[i];
        is_canceled = false;
        continue;
      }
      if (is_voiceless_consonant(s[i - 1]) and is_one_of(s[i], "iu") and
          (s[i + 1] == '$' or is_voiceless_consonant(s[i + 1]))) { // rule 1
        t += string() + "(" + s[i] + ")";
        is_canceled = true;
        continue;
      }
      if (is_voiceless_consonant(s[i - 1]) and is_one_of(s[i], "ao") and
          is_voiceless_consonant(s[i + 1]) and s[i + 2] == s[i]) { // rule 2
        t += string() + "(" + s[i] + ")";
        is_canceled = true;
        continue;
      }
      t += s[i];
    }
    cerr << " -> " << t << endl;
    cout << t << endl;
  }
  return 0;
}