alexjercan/bugnet huggingface dataset:
Problem p00100 (C++) — buggy submission, verdict: Runtime Error

#include <memory.h>
#include <stdio.h>
int main() {
  int n, i, j, k, e[1000], p[1000], q[1000];
  int c[1000], count = 0, count2 = 0;
  int gokei = 0;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &e[i], &p[i], &q[i]);
      gokei = p[i] * q[i];
      for (j = 0; j < i; j++) {
        if (e[i] == e[j]) {
          gokei += p[j] * q[j];
        }
      }
      for (k = 0; k < count; k++) {
        if (e[i] == c[k]) {
          goto a;
        }
      }
      if (gokei >= 1000000) {
        c[count] = e[i];
        count++;
      }
    a:
      gokei = 0;
    }
    for (i = 0; i < count; i++) {
      printf("%d\\n", c[i]);
    }
    if (count == 0) {
      printf("NA\\n");
    }
    count = 0;
    memset(c, 0, sizeof(c));
  }

  return 0;
}

Error: 0

Fixed submission:

#include <memory.h>
#include <stdio.h>
int main() {
  int n, i, j, k, e[100], p[100], q[100];
  int c[100], count = 0, count2 = 0;
  int gokei = 0;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &e[i], &p[i], &q[i]);
      gokei = p[i] * q[i];
      for (j = 0; j < i; j++) {
        if (e[i] == e[j]) {
          gokei += p[j] * q[j];
        }
      }
      for (k = 0; k < count; k++) {
        if (e[i] == c[k]) {
          goto a;
        }
      }
      if (gokei >= 1000000) {
        c[count] = e[i];
        count++;
      }
    a:
      gokei = 0;
    }
    for (i = 0; i < count; i++) {
      printf("%d\\n", c[i]);
    }
    if (count == 0) {
      printf("NA\\n");
    }
    count = 0;
    memset(c, 0, sizeof(c));
  }

  return 0;
}
Problem p00100 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
  if (a < b)
    a = b;
}
template <class T, class C> void chmin(T &a, C b) {
  if (b < a)
    a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }

int main() {
  int n;
  while (cin >> n && n) {
    bool f = true;
    set<int> table;
    vector<ll> v(4005, 0);

    rep(i, n) {
      int num;
      ll a, s;
      cin >> num >> a >> s;

      if (table.find(num) == table.end()) {
        v[num] += a * s;
        if (1000000 <= v[num]) {
          f = false;
          table.insert(num);
          cout << num << endl;
        }
      }
    }

    if (f)
      cout << "NA" << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
  if (a < b)
    a = b;
}
template <class T, class C> void chmin(T &a, C b) {
  if (b < a)
    a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }

int main() {
  int n;
  while (cin >> n && n) {
    bool f = true;

    rep(i, n) {
      ll a, s, num;
      cin >> num >> a >> s;

      if (1000000 / a <= s) {
        f = false;
        cout << num << endl;
      }
    }

    if (f)
      cout << "NA" << endl;
  }
}
Problem p00101 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

int main() {
  std::string str;
  u_int data_num;
  std::cin >> data_num;
  std::cin.ignore();
  for (u_int i = 0; i < data_num; ++i) {
    int loc = 0;
    std::getline(std::cin, str);
    while ((loc = str.find("Hoshino", loc)) != -1) {
      str[loc + 6] = 'a';
    }
    std::cout << str << std::endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>

int main() {
  std::string str;
  int data_num;
  std::cin >> data_num;
  std::cin.ignore();
  for (int i = 0; i < data_num; ++i) {
    u_int loc = 0;
    std::getline(std::cin, str);
    while (1) {
      loc = str.find("Hoshino", loc);
      if (loc == std::string::npos) {
        break;
      }
      str[loc + 6] = 'a';
    }
    std::cout << str << std::endl;
  }

  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

typedef unsigned int uint;

int main() {
  int n, idx;
  string s;
  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, s);
    idx = -7;
    while ((idx = s.find("Hoshino", idx + 7)) != string::npos)
      s.replace(idx, 7, "Hoshina");
    cout << s << endl;
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::replace: __pos (which is 4294967295) > this->size() (which is 7)


Fixed submission:

#include <iostream>
#include <string>
using namespace std;

typedef unsigned int uint;

int main() {
  int n;
  string s;
  uint idx;
  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, s);
    idx = -1;
    while ((idx = s.find("Hoshino")) != string::npos)
      s.replace(idx, 7, "Hoshina");
    cout << s << endl;
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  int n;
  int c_pos;
  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, s);
    while ((c_pos = s.find("Hoshino")) != string::npos) {
      s.replace(c_pos, 7, "Hoshina");
    }
    cout << s << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  string x;
  int i = 0, n;
  cin >> n;
  for (i = 0; i < n;) {
    x = "";
    cin >> x;
    cin.ignore();

    string::size_type pos = x.find("Hoshino");
    while (pos != string::npos) {
      x.replace(pos, 7, "Hoshina");
      pos = x.find("Hoshino", pos + 7);
    }
    cout << x << endl;
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

const string src = "Hoshino";
bool check(string str, int n, int m) {
  if (str[n] == src[m]) {
    if (m == 6)
      return true;
    return check(str, n + 1, m + 1);
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  cin.ignore();
  string *str = new string[n];
  for (int i = 0; i < n; i++) {
    getline(cin, str[i]);
    for (int j = 0; j < str[i].size(); j++) {
      if (check(str[i], j, 0)) {
        str[i][j + 6] = 'a';
        j += 5;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << str[i] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

const string src = "Hoshino";
bool check(string str, int n, int m) {
  if (str[n] == src[m]) {
    if (m == 6)
      return true;
    return check(str, n + 1, m + 1);
  }
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  string *str = new string[n];
  for (int i = 0; i < n + 1; i++) {
    getline(cin, str[i]);
    for (int j = 0; j < str[i].size(); j++) {
      if (check(str[i], j, 0)) {
        str[i][j + 6] = 'a';
        j += 5;
      }
    }
  }
  for (int i = 0; i < n + 1; i++) {
    cout << str[i];
    if (i)
      cout << endl;
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  cin.ignore();
  rep(i, n) {
    string s;
    getline(cin, s);

    if (s.length() < 6) {
      cout << s << endl;
    } else {
      rep(j, s.length() - 6) {
        if (s[j] == 'H' && s[j + 1] == 'o' && s[j + 2] == 's' &&
            s[j + 3] == 'h' && s[j + 4] == 'i' && s[j + 5] == 'n' &&
            s[j + 6] == 'o') {
          s[j + 6] = 'a';
          j += 6;
        }
      }
      cout << s << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  cin.ignore();
  rep(i, n) {
    string s;
    getline(cin, s);

    rep(j, s.length() - 6) {
      if (s[j] == 'H' && s[j + 1] == 'o' && s[j + 2] == 's' &&
          s[j + 3] == 'h' && s[j + 4] == 'i' && s[j + 5] == 'n' &&
          s[j + 6] == 'o') {
        s[j + 6] = 'a';
        j += 6;
      }
    }

    cout << s << endl;
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  string str;
  int n;

  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, str);
    for (int j = 0; j < (int)str.size(); j++) {
      string key = str.substr(j, 7), repl;
      if (key == "Hoshino") {
        repl = "Hoshina";
        for (int k = 0; k < 7; k++) {
          str[j + k] = repl[k];
        }
      }
    }
    cout << str << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  string str;
  int n;

  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, str);
    for (int j = 0; j < (int)str.size(); j++) {
      string key = str.substr(j, 7), repl;
      if (key == "Hoshino") {
        repl = "Hoshina";
        for (int k = 0; k < n; k++) {
          str[j + k] = repl[k];
        }
      }
    }
    cout << str << endl;
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;
  scanf("%d ", &n);
  string a[n];
  for (int i = 0; i < n; i++) {
    getline(cin, a[i]);
    while (1) {
      int index = 0;
      index = a[i].find("Hoshino", index);
      if ((int)string::npos == index)
        break;
      a[i][index + 6] = 'a';
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << "\\n";
  }
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;
  scanf("%d ", &n);
  string a[2];
  for (int i = 0; i < n; i++) {
    getline(cin, a[i]);
    while (1) {
      string::size_type index;
      index = a[i].find("Hoshino", index);
      if (string::npos == index)
        break;
      a[i][index + 6] = 'a';
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << "\\n";
  }
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
using namespace std;

int main(void) {
  int n;
  char str[10000], c;
  char *t;

  scanf("%d\\n", &n);

  for (int i = 0; i < n; i++) {
    gets(str);

    while (t = strstr(str, "Hoshino"), t) {
      t[6] = 'a';
    }
    printf("%s\\n", str);
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 1) > this->size() (which is 0)


Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main(void) {
  string str;
  int n;

  cin >> n;
  while (--n, n >= 0) {
    getline(cin, str);

    for (int i = 0; i < str.length() - 8; i++) {
      if (str.substr(i, 7) == "Hoshino")
        str[i + 6] = 'a';
    }
    cout << str << endl;
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
string S;
int n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    S = "";
    while (S == "") {
      getline(cin, S);
    }
    if (S.size() >= 7) {
      for (int i = 0; i < S.size() - 6; i++) {
        if (S.substr(i, 7) == "Hoshino") {
          S[i + 6] = 'a';
        }
      }
    }
    cout << S << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 2) > this->size() (which is 1)


Fixed submission:

#include <iostream>
#include <string>
using namespace std;
string S;
int main() {
  while (getline(cin, S)) {
    for (int i = 0; i < S.size() - 6; i++) {
      if (S.substr(i, 7) == "Hoshino") {
        S[i + 6] = 'a';
      }
    }
    cout << S << endl;
  }
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int n;
  char str[1024];

  scanf("%d ", &n);

  for (int i = 0; i < n; i++) {
    fgets(str, sizeof(str), stdin);

    int len = strlen(str);
    for (int j = 0; j < len - 6; j++) {
      if (strncmp(&str[j], "Hoshino", 7) == 0) {
        str[j + 6] = 'a';
      }
    }

    cout << str;
  }

  return (0);
}

Error: -11

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int n;
  char str[1001];

  cin >> n;

  for (int i = 0; i < n; i++) {
    fgets(str, sizeof(str), stdin);

    for (int j = 0; j < strlen(str) - 6; j++) {
      if (strncmp(&str[j], "Hoshino", 7) == 0) {
        str[j + 6] = 'a';
      }
    }

    cout << str;
  }

  return (0);
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

string s;

string Replace(string s1, string s2, string s3) {
  string ::size_type pos(s1.find(s2));
  while (pos != string ::npos) {
    s1.replace(pos, s2.size(), s3);
    pos = s1.find(s2, pos + s3.size());
  }
  return s1;
}

signed main() {
  int n = 0;
  scanf("%d\\n", &n);
  while (0 < n) {
    getline(cin, s);
    s = Replace(s, "Hoshino", "Hoshina");
    cout << s << endl;
    n--;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

string s;

signed main() {
  while (s != "\\n") {
    cin >> s;
    if (s == "Hoshino") {
      cout << "Hoshina" << ' ';
    } else {
      cout << s << ' ';
    }
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

signed main() {
  int n;
  scanf("%d%*c", &n);
  for (int i = 0; i < n; ++i) {
    string s;
    getline(cin, s);
    regex re("Hoshino");
    cout << regex_replace(s, re, "Hoshina") << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
  int n;
  scanf("%d%*c", &n);
  for (int i = 0; i < n; ++i) {
    string s;
    getline(cin, s);
    regex re("Hoshino");
    cout << regex_replace(s, re, "Hoshina") << endl;
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> P;

typedef long long int li;

int main() {
  int n;
  string hos = "Hoshino";

  cin >> n;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);

    int k = s.size() + 1 - hos.size();
    for (int i = 0; i < k; i++) {
      if (s.substr(i, hos.size()) == hos) {
        s[i + hos.size() - 1] = 'a';
      }
    }

    cout << s << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> P;

typedef long long int li;

int main() {
  int n;
  string hos = "Hoshino";

  cin >> n;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);

    for (int i = 0; i < s.size() + 1 - hos.size(); i++) {
      if (s.substr(i, hos.size()) == hos) {
        s[i + hos.size() - 1] = 'a';
      }
    }

    cout << s << endl;
  }

  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  string s;
  int n;
  cin >> n;
  cin.ignore();
  rep(i, n) {
    getline(cin, s);
    int size = s.size();
    rep(j, size - 6) {
      string point = s.substr(j, 7);
      if (point == "Hoshino") {
        point = "Hoshina";
        s.replace(j, 7, point);
      }
    }
    cout << s << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  long double n;
  string spot;
  cin >> n;
  cin.ignore();
  for (long i = 0; i < n; i++) {
    getline(cin, spot);
    for (long j = 0; j <= spot.size() - 7; j++) {
      string str = "";
      for (long k = j; k < j + 7; k++) {
        str += spot[k];
      }
      if (str == "Hoshino") {
        spot[j + 6] = 'a';
      }
    }
    cout << spot << '\\0' << endl;
  }
  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main() {
  int n;
  cin >> n;
  char c;
  scanf("%c", &c);
  rep(p, n) {
    string s;
    getline(cin, s);
    rep(i, s.length()) {
      int b = (int)s.find("Hoshino", i);
      if (b != -1) {
        s.replace(b, 7, "Hoshina");
        i += 6;
      }
    }
    cout << s << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main() {
  int n;
  cin >> n;
  char c;
  scanf("%c", &c);
  rep(p, n) {
    string s;
    getline(cin, s);
    rep(i, s.length()) {
      int b = (int)s.find("Hoshino", i);
      if (b != -1) {
        s.replace(b + i, 7, "Hoshina");
        i += 7;
      }
    }
    cout << s << endl;
  }
}
Problem p00101 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, i = 0, index;
  string s;
  cin >> n;
  cin.ignore();

  while (i < n) {
    getline(cin, s);
    while (true) {
      string::size_type index = s.find("Hoshino");
      if (index != string ::npos) {
        s.replace(index, 7, "Hoshina");
      } else {
        break;
      }
    }
    cout << s << endl;
    i++;
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, i, index;
  string s;
  cin >> n;

  i = 0;
  while (i < n) {
    getline(cin, s);
    while (true) {
      string::size_type index = s.find("Hoshino");
      if (index != string ::npos) {
        s.replace(index, 7, "Hoshina");
      } else {
        break;
      }
    }
    cout << s << endl;
  }

  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

int main() {
  int n; // the number of datasets
  std::cin >> n;
  std::cin.ignore();

  for (int i = 0; i < n; ++i) {
    std::string text;
    std::getline(std::cin, text); // input

    int text_size = text.size();
    int moji = text.find("Hoshino");
    while (moji != std::string::npos) {
      text.replace(moji, 7, "Hoshina");
      moji = text.find("Hoshino", moji);
    }

    std::cout << text << std::endl; // output
  }

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 7)


Fixed submission:

#include <iostream>
#include <string>

int main() {
  int n; // the number of datasets
  std::cin >> n;
  std::cin.ignore();

  for (int i = 0; i < n; ++i) {
    std::string text;
    std::getline(std::cin, text); // input

    int text_size = text.size();
    int moji = 0;
    while (moji < text_size) {
      moji = text.find("Hoshino", moji);
      text.replace(moji, 7, "Hoshina");
    }

    std::cout << text << std::endl; // output
  }

  return 0;
}
Problem p00101 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  string str, hosino = "Hoshino";

  cin >> n;
  getline(cin, str); // cinで残された改行コード回収

  for (int o = 0; o < n; o++) {
    getline(cin, str);
    if (str.size() >= 7) {
      for (int i = 0; i < str.size() - 6; i++) {
        int k = i, j = 0;
        while (j <= 6 && str[k] == hosino[j]) {
          k++;
          j++;
        }
        if (j == 7)
          str[k - 1] = 'a';
      }
    }
    cout << str << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  string str, hosino = "Hoshino";

  cin >> n;
  getline(cin, str); // cinで残された改行コード回収

  for (int o = 0; o < n; o++) {
    getline(cin, str);
    for (int i = 0; i < str.size() - 6; i++) {
      int k = i, j = 0;
      while (j <= 6 && str[k] == hosino[j]) {
        k++;
        j++;
      }
      if (j == 7)
        str[k - 1] = 'a';
    }
    cout << str << endl;
  }

  return 0;
}