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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int n, a = 0, b = 0, c = 0, o = 0, x, y, z, w;
  char s[3];
  while (scanf("%d,%s", &n, s) != EOF) {
    if (s[1] == 'B')
      c++;
    else if (s[0] == 'A')
      a++;
    else if (s[0] == 'B')
      b++;
    else
      o++;
  }
  cout << a << endl << b << endl << c << endl << o << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int n, a = 0, b = 0, c = 0, o = 0, x, y, z, w;
  char s[2];
  while (scanf("%d,%s", &n, s) != EOF) {
    if (s[1] == 'B')
      c++;
    else if (s[0] == 'A')
      a++;
    else if (s[0] == 'B')
      b++;
    else
      o++;
  }
  cout << a << endl << b << endl << c << endl << o << endl;
}
Problem p00049 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

void solve() {
  int count[4] = {0};
  int num;
  string blood;
  while (scanf("%d,", &num) != EOF) {
    cin >> blood;
    if (blood == "A") {
      ++count[0];
    } else if (blood == "B") {
      ++count[1];
    } else if (blood == "AB") {
      ++count[2];
    } else {
      ++count[3];
    }
  }
  cout << count[0] << endl;
  cout << count[1] << endl;
  cout << count[2] << endl;
  cout << count[3] << endl;
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

void solve() {
  int count[4] = {0};
  int num;
  string blood;
  while (scanf("%d,", &num)) {
    cin >> blood;
    if (blood == "A") {
      ++count[0];
    } else if (blood == "B") {
      ++count[1];
    } else if (blood == "AB") {
      ++count[2];
    } else {
      ++count[3];
    }
  }
  cout << count[0] << endl;
  cout << count[1] << endl;
  cout << count[2] << endl;
  cout << count[3] << endl;
}

int main() {
  solve();
  return (0);
}
Problem p00049 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int num;
  int blood_a = 0, blood_b = 0, blood_ab = 0, blood_o = 0;
  char blood_type[3];
  while (scanf("%d,%s", &num, blood_type) != EOF) {
    if (blood_type[0] == 'A') {
      if (blood_type[1] == 'B')
        blood_ab++;
      else
        blood_a++;
    } else if (blood_type[0] == 'B')
      blood_b++;
    else if (blood_type[0] == 'O')
      blood_o++;
  }
  cout << blood_a << endl
       << blood_b << endl
       << blood_ab << endl
       << blood_o << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int num;
  int blood_a = 0, blood_b = 0, blood_ab = 0, blood_o = 0;
  char blood_type[3];
  while (scanf("%d,%s", &num, blood_type)) {
    if (blood_type[0] == 'A')
      blood_a++;
    else if (blood_type[0] == 'B')
      blood_b++;
    else if (blood_type == "AB")
      blood_ab++;
    else if (blood_type[0] == 'O')
      blood_o++;
  }
  cout << blood_a << endl
       << blood_b << endl
       << blood_ab << endl
       << blood_o << endl;
}
Problem p00049 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int a, A = 0, B = 0, O = 0, AB = 0;
  char c[10] = {0};
  while (scanf("%d,%s", &a, c) != EOF) {
    if (strlen(c) == 2)
      AB++;
    else if (c[0] == 'B')
      B++;
    else if (c[0] == 'O')
      O++;
    else
      A++;
  }
  cout << A << endl << B << endl << AB << endl << O << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, A = 0, B = 0, O = 0, AB = 0;
  char c;
  while (scanf("%d,%c", &a, &c) != EOF) {
    if (c == 'A')
      A++;
    else if (c == 'B')
      B++;
    else if (c = -'O')
      O++;
    else
      AB++;
  }
  cout << A << endl << B << endl << O << endl << AB << endl;
  return 0;
}
Problem p00049 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  int A = 0, B = 0, AB = 0, O = 0, x;
  char str[3];
  while (scanf("%d,%s", &x, str) != EOF) {
    if (!strcmp(str, "A"))
      A++;
    else if (!strcmp(str, "B"))
      B++;
    else if (!strcmp(str, "AB"))
      AB++;
    else if (!strcmp(str, "O"))
      O++;
  }
  printf("%d\\n%d\\n%d\\n%d\\n", A, B, AB, O);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a[4], x;
  char c[2];
  for (int i = 0; i < 4; i++)
    a[i] = 0;
  while (scanf("%d,%s", &x, c), x) {
    cout << x << ' ' << c[0] << endl;
    if (c[0] == 'A') {
      if (c[1] == 'B')
        a[2]++;
      else
        a[0]++;
    } else if (c[0] == 'B')
      a[1]++;
    else if (c[0] == 'O')
      a[3]++;
  }

  cout << a[0] << endl << a[1] << endl << a[2] << endl << a[3] << endl;
  return 0;
}
Problem p00049 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char commma;
  int num;
  string blood;
  int a = 0, b = 0, ab = 0, o = 0;
  while (1) {
    cin >> num >> commma >> blood;
    if (cin.eof())
      break; //??\\????????????????????°break
    if (blood == "A")
      a++;
    else if (blood == "B")
      b++;
    else if (blood == "AB")
      ab++;
    else
      o++;
  }
  cout << a << endl;
  cout << b << endl;
  cout << ab << endl;
  cout << o << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a = 0, b = 0, o = 0, ab = 0, k;
  string s;
  while (true) {
    cin >> s;
    if (s.size() == 0)
      break;
    if (s[2] == 'A' && s[3] != 'B')
      a++;
    else if (s[2] == 'B')
      b++;
    else if (s[2] == 'A')
      ab++;
    else
      o++;
  }
  cout << a << endl;
  cout << b << endl;
  cout << ab << endl;
  cout << o << endl;
  return 0;
}
Problem p00049 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  char str[10];
  int a, p = 0, q = 0, r = 0, s = 0;
  while (scanf("%d,%s", &a, str) != EOF) {
    if (strcmp(str, "A") == 0) {
      p++;
    } else if (strcmp(str, "B") == 0) {
      q++;
    } else if (strcmp(str, "AB") == 0) {
      r++;
    } else if (strcmp(str, "O") == 0) {
      s++;
    }
  }
  printf("%d\\n%d\\n%d\\n%d\\n", p, q, r, s);
  return 0;
}

Error: -6
free(): invalid pointer


Fixed submission:

#include <cstdio>
#include <string>
using namespace std;
int main() {
  string str;
  int a, p = 0, q = 0, r = 0, s = 0;
  while (scanf("%d,%s", &a, &str) != EOF) {
    if (str == "A") {
      p++;
    } else if (str == "B") {
      q++;
    } else if (str == "AB") {
      r++;
    } else if (str == "O") {
      s++;
    }
  }
  return 0;
}
Problem p00049 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int num;
  char blood[100];
  char row[1000];
  map<string, int> type;
  type.insert(make_pair("A", 0));
  type.insert(make_pair("B", 0));
  type.insert(make_pair("O", 0));
  type.insert(make_pair("AB", 0));
  while (cin >> row) {
    if (cin.eof())
      break;
    sscanf(row, "%d,%s", &num, &blood);
    type[blood]++;
  }
  cout << type["A"] << endl;
  cout << type["B"] << endl;
  cout << type["AB"] << endl;
  cout << type["O"] << endl;
  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;

int main() {
  int num;
  string blood;
  char row[1000];
  map<string, int> type;
  type.insert(make_pair("A", 0));
  type.insert(make_pair("B", 0));
  type.insert(make_pair("O", 0));
  type.insert(make_pair("AB", 0));
  while (cin >> row) {
    if (cin.eof())
      break;
    sscanf(row, "%d,%s", &num, &blood);
    type[blood]++;
  }
  cout << type["A"] << endl;
  cout << type["B"] << endl;
  cout << type["AB"] << endl;
  cout << type["O"] << endl;
  return 0;
}
Problem p00050 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s;
  getline(cin, s);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a' && s[i + 1] == 'p' && s[i + 2] == 'p' && s[i + 3] == 'l' &&
        s[i + 4] == 'e') {
      cout << "peach";
      i += 4;
    } else if (s[i] == 'p' && s[i + 1] == 'e' && s[i + 2] == 'a' &&
               s[i + 3] == 'c' && s[i + 4] == 'h') {
      cout << "apple";
      i += 4;
    } else
      cout << s[i];
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  for (string s;; cin >> s) {
    if (s == "peach")
      cout << "apple";
    else if (s == "apple")
      cout << "peach";
    else
      cout << s;
    cout << ' ';
  }
  cout << endl;
  char c;
  cin >> c;
  return 0;
}
Problem p00050 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str;
  getline(cin, str);
  for (int i = 0; i < str.size() - 4; i++) {
    if (str.substr(i, 5) == "apple") {
      str.replace(i, 5, "peach");
      // cout << str << i << endl;
    } else if (str.substr(i, 5) == "peach") {
      str.replace(i, 5, "apple");
      // cout << str << i << endl;
    }
  }
  cout << str << endl;
}

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 3)


Fixed submission:

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

int main() {
  string str;
  string word[1111];
  getline(cin, str);
  stringstream ss;
  int cou = 0;
  ss << str;
  while (!ss.eof()) {
    string tmp;
    ss >> tmp;
    word[cou] = tmp;
    cou++;
  }
  unsigned int loc;
  for (int i = 0; i < cou; i++) {
    loc = word[i].find("apple", 0);
    if (loc != string::npos) {
      word[i].replace(loc, 5, "peach");
      cout << word[i];
    } else {
      loc = word[i].find("peach", 0);
      if (loc != string::npos) {
        word[i].replace(loc, 5, "apple");
        cout << word[i];
      } else
        cout << word[i];
    }
    if (i != cou - 1)
      cout << " ";
  }
  cout << endl;
}
Problem p00050 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  unsigned int a_pos = 0, p_pos = 0;
  string sent;

  getline(cin, sent);

  for (int i = 0; i + 4 < sent.length(); i++) {
    if (sent.substr(i, 5) == "apple") {
      sent.replace(i, 5, "peach");
    } else if (sent.substr(i, 5) == "peach") {
      sent.replace(i, 5, "apple");
    }
  }

  cout << sent << 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 55)


Fixed submission:

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

int main() {
  unsigned int a_pos = 0, p_pos = 0;
  string sent, sch = "apple";

  getline(cin, sent);

  while (1) {
    a_pos = sent.find("apple", a_pos);
    p_pos = sent.find("peach", p_pos);
    if (a_pos == string::npos && p_pos == string::npos)
      break;

    if (a_pos != string::npos)
      sent.replace(a_pos, 5, "peach");
    if (p_pos != string::npos)
      sent.replace(p_pos, 5, "apple");

    if (a_pos != string::npos && p_pos != string::npos) {
      a_pos = max(a_pos, p_pos) + 1;
      p_pos = a_pos;
    }
  }

  cout << sent << endl;
  return 0;
}
Problem p00050 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
const int MAX_S = 2000;
int main() {
  char s[MAX_S + 1];
  fgets(s, MAX_S, stdin);
  for (int i = 0; i + 4 < strlen(s); i++) {
    if (s[i] == 'a' && s[i + 1] == 'p' && s[i + 2] == 'p' && s[i + 3] == 'l' &&
        s[i + 4] == 'e') {
      s[i] = 'p';
      s[i + 1] = 'e';
      s[i + 2] = 'a';
      s[i + 3] = 'c';
      s[i + 4] = 'h';
    } else if (s[i] == 'p' && s[i + 1] == 'e' && s[i + 2] == 'a' &&
               s[i + 3] == 'c' && s[i + 4] == 'h') {
      s[i] = 'a';
      s[i + 1] = 'p';
      s[i + 2] = 'p';
      s[i + 3] = 'l';
      s[i + 4] = 'e';
    }
  }
  cout << s;
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
int main() {
  char s[10000];
  int i = 0;
  fgets(s, 2000, stdin);
  while (1) {
    if (s[i] == '.')
      break;
    else if (s[i] == 'a') {
      if (s[i + 1] == 'p')
        if (s[i + 2] == 'p')
          if (s[i + 3] == 'l')
            if (s[i + 4] == 'e') {
              printf("peach");
              i += 5;
            }
    } else if (s[i] == 'p') {
      if (s[i + 1] == 'e')
        if (s[i + 2] == 'a')
          if (s[i + 3] == 'c')
            if (s[i + 4] == 'h') {
              printf("apple");
              i += 5;
            }
    } else {
      putchar(s[i++]);
    }
  }
  putchar('.');
  return 0;
}
Problem p00050 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char input[2000];
  cin.getline(input, 1000);
  for (int i = 0; input[i] != '\\0'; i++) {
    if (!strncmp(&input[i], "apple", 5)) {
      strncpy(&input[i], "peach", 5);
    } else if (!strncmp(&input[i], "peach", 5)) {
      strncpy(&input[i], "apple", 5);
    }
  }
  printf("%s\\n", input);
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  char input[2000];
  cin.getline(input, 1000);
  for (int i = 0; input[i] != '\\n'; i++) {
    if (!strncmp(&input[i], "apple", 5)) {
      strncpy(&input[i], "peach", 5);
    } else if (!strncmp(&input[i], "peach", 5)) {
      strncpy(&input[i], "apple", 5);
    }
  }
  printf("%s\\n", input);
  return 0;
}
Problem p00050 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string s, s1, s2;
  getline(cin, s);
  s2 = s1 = s;
  while (s1.find("apple") != std::string::npos) {
    s.replace(s1.find("apple"), 5, "peach");
    s1.replace(s1.find("apple"), 5, "peach");
  }
  while (s2.find("peach") != std::string::npos) {
    s.replace(s2.find("peach"), 5, "apple");
    s2.replace(s2.find("peach"), 5, "apple");
  }
  cout << s << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  unsigned int aloc[200], ploc[200], idx = 0, a, b;
  string s;
  getline(cin, s);
  for (a = 0; aloc[a] <= s.length(); a++) {
    aloc[a] = s.find("apple", idx);
    if (aloc[a] == string::npos) {
      break;
    } else {
      idx = aloc[a] + 5;
    }
  }
  idx = 0;
  cout << aloc[1] << endl;
  for (b = 0; idx + 5 <= s.length(); b++) {
    ploc[b] = s.find("peach", idx);
    if (ploc[b] == string::npos) {
      break;
    } else {
      idx = ploc[b] + 5;
    }
  }
  for (int i = 0; i < a; i++) {
    s.replace(aloc[i], 5, "peach");
  }
  for (int i = 0; i < b; i++) {
    s.replace(ploc[i], 5, "apple");
  }
  cout << s << endl;
  return 0;
}
Problem p00050 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {

  queue<string> data;
  string str;

  while (cin >> str) {
    int i;
    if (str.find("hoge", 0) == 0) {
      break;
    }
    if ((i = str.find("apple", 0)) > -1) {
      str.replace(i, 5, "peach");
    } else if ((i = str.find("peach", 0)) > -1) {
      str.replace(i, 5, "apple");
    }

    data.push(str);
  }
  int num = data.size();
  for (int i = 0; i < num - 1; i++) {
    cout << data.front();
    data.pop();
    cout << " ";
  }
  cout << data.front() << endl;

  return 0;
}

/*
Sample Input
the cost of one peach is higher than that of one apple.
Output for the Sample Input
the cost of one apple is higher than that of one peach.
*/

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {

  string str;
  // データ入力
  getline(cin, str);

  char *data = new char(str.size() + 10);

  for (int i = 0; i < str.size(); i++) {
    data[i] = str[i];
  }

  // 変換
  for (int i = 0; i < str.size() - 5; i++) {
    if (data[i] == 'a' && data[i + 1] == 'p' && data[i + 2] == 'p' &&
        data[i + 3] == 'l' && data[i + 4] == 'e') {
      data[i] = 'p';
      data[i + 1] = 'e';
      data[i + 2] = 'a';
      data[i + 3] = 'c';
      data[i + 4] = 'h';
      i += 4;
    } else if (data[i] == 'p' && data[i + 1] == 'e' && data[i + 2] == 'a' &&
               data[i + 3] == 'c' && data[i + 4] == 'h') {
      data[i] = 'a';
      data[i + 1] = 'p';
      data[i + 2] = 'p';
      data[i + 3] = 'l';
      data[i + 4] = 'e';
      i += 4;
    }
  }
  for (int i = 0; i < str.size(); i++) {
    cout << data[i];
  }

  return 0;
}

/*
Sample Input
the cost of one peach is higher than that of one apple.
Output for the Sample Input
the cost of one apple is higher than that of one peach.
*/
Problem p00050 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  int x;
  string a;
  getline(cin, a);
  for (x = 0; x < a.size(); x++) {
    if (a[x] == 'a' && a[x + 1] == 'p' && a[x + 2] == 'p' && a[x + 3] == 'l' &&
        a[x + 4] == 'e') {
      a[x] = 'p';
      a[x + 1] = 'e';
      a[x + 2] = 'a';
      a[x + 3] = 'c';
      a[x + 4] = 'h';
    } else if (a[x] == 'p' && a[x + 1] == 'e' && a[x + 2] == 'a' &&
               a[x + 3] == 'c' && a[x + 4] == 'h') {
      a[x] = 'a';
      a[x + 1] = 'p';
      a[x + 2] = 'p';
      a[x + 3] = 'l';
      a[x + 4] = 'e';
    }
  }
  cout << a << endl;
  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 55)


Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string a;
  getline(cin, a);
  while (1) {
    if (a.find("apple")) {
      a.replace(a.find("apple"), 5, "peach");
    } else if (a.find("peach")) {
      a.replace(a.find("peach"), 5, "apple");
    }
  }
  cout << a << endl;
  return 0;
}
Problem p00050 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define rp(a) while (a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define MAX 1000000
bool sosu[MAX];
int main() {
  string s;
  getline(cin, s);
  if (s.size() < 5) {
    cout << s << endl;
    return 0;
  }

  rep(i, s.size() - 4) {
    string tmp = s.substr(i, 5);
    if (tmp == "apple")
      s.replace(i, 5, "peach");
    else if (tmp == "peach")
      s.replace(i, 5, "apple");
  }
  cout << s << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define rp(a) while (a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define MAX 1000000
bool sosu[MAX];
int main() {
  string s;
  getline(cin, s);
  while (1) {
    int it;
    if ((it = s.find("apple")) != string::npos)
      s.replace(it, 5, "peach");
    else if ((it = s.find("peach")) != string::npos)
      s.replace(it, 5, "apple");
    else
      break;
  }
  cout << s << endl;
}
Problem p00050 (C++) — buggy submission, verdict: Runtime Error

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

int set(string str, string a, int loc) { return str.find(a, loc); }

string rep(string str, string tar, string rp) {
  int loc = 0;
  while ((loc = set(str, tar, loc)) != string::npos)
    str.replace(loc, tar.length(), rp);
  return str;
}

int main() {
  string str, a = "apple", p = "peach", tmp = ".....";
  unsigned int loc = 0;
  getline(cin, str);
  str = rep(str, a, tmp);
  str = rep(str, p, a);
  str = rep(str, tmp, p);
  cout << str << 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 55)


Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, a = "apple", p = "peach", tmp = ".....";
  unsigned int loc = 0;
  getline(cin, str);
  while ((loc = str.find(a, loc)) != string::npos)
    str.replace(loc, a.length(), tmp);
  loc = 0;
  while ((loc = str.find(p, loc)) != string::npos)
    str.replace(loc, p.length(), a);
  loc = 0;
  while ((loc = str.find(tmp, loc)) != string::npos)
    str.replace(loc, tmp.length(), p);
  cout << str << endl;
  return 0;
}