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

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

char x[200010];
int main() {
  scanf("%s", x + 1);
  int a = strlen(x + 1);
  for (int i = 1; i <= a; i++)
    if (x[i] == '?')
      x[i] = 'D';
  for (int i = 1; i <= a; i++)
    printf("%c", x[i]);
}

Error: WA

Fixed submission:

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

char x[100010];
int main() {
  scanf("%s", x + 1);
  int a = strlen(x + 1);
  for (int i = 1; i <= a; i++)
    if (x[i] == '?')
      x[i] = 'D';
  for (int i = 1; i <= a; i++)
    printf("%c", x[i]);
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string t;
  cin >> t;
  long num = t.size() - 1;
  rep(i, t.size()) {
    if (t.at(i) == '?') {
      if (i == 0) {
        t.at(i) = 'D';
      } else if (i == num) {
        t.at(i) = 'D';
      } else {
        if (t.at(i - 1) == 'P') {
          t.at(i) = 'D';
        } else if (t.at(i + 1) == 'P') {
          t.at(i) = 'D';
        } else {
          t.at(i) = 'D';
        }
      }
    }
  }
  cout << t << endl;
  return 0;
}

Error: WA

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string t;
  cin >> t;
  long num = t.size() - 1;
  rep(i, t.size()) {
    if (t.at(i) == '?') {
      if (i == 0) {
        if (t.at(i + 1) == 'P') {
          t.at(i) = 'D';
        } else {
          t.at(i) = 'D';
        }
      } else if (i == num) {
        t.at(i) = 'D';
      } else {
        if (t.at(i - 1) == 'P') {
          t.at(i) = 'D';
        } else if (t.at(i + 1) == 'P') {
          t.at(i) = 'D';
        } else {
          t.at(i) = 'D';
        }
      }
    }
  }
  cout << t << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <queue>
#define REP(i, n) for (ll i = 1; i <= n; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define ld long double
using namespace std;

int main() {
  string T;
  cin >> T;
  ll ans = 0;
  string ansString = "";
  vector<ll> index;
  rep(i, T.size()) {
    if (T.at(i) == '?') {
      index.push_back(i); // 何番目が？か
    }
  }

  string keep = "";
  keep = T;

  rep(i, index.size()) { keep.at(index[i]) = 'D'; }
  ansString = keep;
  cout << ansString << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <queue>
#define REP(i, n) for (ll i = 1; i <= n; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define ld long double
using namespace std;

ll myCount(string keep) {
  ll score = 0;
  rep(i, keep.size()) {
    if (keep.at(i) == 'D') {
      score++;
      if (i >= 1) {
        if (keep.at(i - 1) == 'P') {
          score++;
        }
      }
    }
  }
  return score;
}

int main() {
  string T;
  cin >> T;
  ll ans = 0;
  string ansString = "";
  vector<ll> index;
  rep(i, T.size()) {
    if (T.at(i) == '?') {
      index.push_back(i); // 何番目が？か
    }
  }
  for (int tmp = 0; tmp < (1 << index.size()); tmp++) {
    bitset<2 * 10 * 10 * 10 * 10 * 10> bs(tmp);
    string cut = bs.to_string().substr(2 * pow(10, 5) - index.size());

    ll score = 0;
    string keep = T;

    rep(i, cut.size()) {
      if (cut.at(i) == '1') {
        keep.at(index[i]) = 'P';
      } else {
        keep.at(index[i]) = 'D';
      }
    }

    score = myCount(keep);
    if (score > ans) {
      ans = score;
      ansString = keep;
    }
  }
  cout << ansString << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P, P>
using namespace std;

int main() {
  string t;
  cin >> t;
  string ans = "";
  rep(i, t.length()) {
    if (t[i] == '?')
      ans += 'D';
    else
      ans += t[i];
  }
  /*
  if(t.length()!=1){
  if(t[0]=='?'){
      if(t[1]=='?') ans+='P';
      else ans+='D';
  }
  else ans+=t[0];
  rep(i,t.length()-2){
      if(t[i+1]=='?'){
      if(ans[i]=='P') ans+='D';
      else if(ans[i]=='D' && t[i+1]=='?') ans+='P';
      else if(ans[i]=='D') ans+='D';
      }
      else ans+=t[i+1];
  }
  if(t[t.length()-1]=='?') ans+='D';
  else ans+=t[t.length()-1];
  }
  if(t[0]=='?') ans+='D';
  else ans+=t[0];
  */
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P, P>
using namespace std;

int main() {
  string t;
  cin >> t;
  string ans = "";
  if (t[0] == '?') {
    if (t[1] == '?')
      ans += 'P';
    else
      ans += 'D';
  } else
    ans += t[0];
  rep(i, t.length() - 2) {
    if (t[i + 1] == '?') {
      if (ans[i] == 'P')
        ans += 'D';
      else if (ans[i] == 'D' && t[i + 1] == '?')
        ans += 'P';
      else if (ans[i] == 'D')
        ans += 'D';
    } else
      ans += t[i + 1];
  }
  if (t[t.length() - 1] == '?')
    ans += 'D';
  else
    ans += t[t.length() - 1];
  cout << ans << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  string t;
  cin >> t;
  rep(i, t.size()) {
    if (t[i] == '?')
      t[i] = 'D';
  }
  cout << t << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long int;

int main() {
  string t;
  cin >> t;
  if (t.at(0) == '?' && t.at(1) == 'D') {
    t.at(0) = 'P';
  } else if (t.at(0) == '?' && t.at(1) == 'P') {
    t.at(0) = 'D';
  } else if (t.at(0) == '?' && t.at(1) == '?') {
    t.at(0) = 'P';
    t.at(1) = 'D';
  }
  for (int i = 1; i < t.size() - 2; i++) {
    if (t.at(i - 1) == 'D' && t.at(i) == '?' && t.at(i + 1) == 'D') {
      t.at(i) = 'P';
    } else if (t.at(i) == '?' && t.at(i + 1) == '?') {
      t.at(i) = 'P';
      t.at(i + 1) = 'D';
      i++;
    } else if (t.at(i) == 'P' && t.at(i + 1) == '?') {
      t.at(i + 1) = 'D';
      i++;
    } else if (t.at(i) == '?' && t.at(i + 1) == 'D') {
      t.at(i) = 'P';
    } else if (t.at(i) == '?' && t.at(i - 1) == 'P') {
      t.at(i) = 'D';
    }
  }
  if (t.at(t.size() - 1) == '?' && t.at(t.size() - 2) == 'P') {
    t.at(t.size() - 1) = 'D';
  } else if (t.at(t.size() - 1) == '?' && t.at(t.size() - 2) == 'D') {
    t.at(t.size() - 1) = 'P';
  }
  cout << t << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

int main() {
  string t;
  cin >> t;
  rep(i, 0, t.size()) {
    if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
  }
  cout << t << endl;
}


Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)

int main() {
  string t;
  cin >> t;

  for (int i = 0; i < t.size(); i++) {
    if (t.at(i) == '?') {
      if (t.at(i - 1) == 'P') {
        cout << "D";
      }
      if (t.at(i - 1) == 'D' && t.at(i + 1) == '?') {
        cout << "P";
      }
      if (t.at(i - 1) == 'D' && t.at(i + 1) == 'D') {
        cout << "P";
      }
      if (t.at(i - 1) == '?' && t.at(i + 1) == 'P') {
        cout << "D";
      }
      // 一番最初にある時
      if (i == 0 && t.at(i + 1) == 'P') {
        cout << "D";
      }
      if (i == 0 && t.at(i + 1) == 'D') {
        cout << "P";
      }
      // 最後にある時
      if (t.at(t.size() - 1) == 'D' || t.at(t.size() - 1) == 'P') {
        cout << "D";
      }
    }

    if (t.at(i) != '?') {
      cout << t.at(i);
    }
  }
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

// c++は戻り値に配列はだめ
/*
char* solve(){
    int n_10 = pow(10,5);
    int MAX_N = 2*n_10;

    char s[MAX_N+1];
    scanf("%s", s);
    //'D'としないとだめ.
    //前後の関係があるため愚直に数えた方が合理的.

    int res = 0;
    for(int i=0; i < MAX_N; i++){
        if(s[i] == 'P'){
            if(s[i+1] == 'D' || s[i+1] == '?'){
                res += 2;
            }
        }
        if(s[i] == 'D' || s[i] == '?'){
            res += 1;
        }
    }
   for(int i=0; i < MAX_N; i++){
       if(s[i] == '?'){
           s[i] = 'D';
       }
   }
    return s;
}
*/

int main() {
  int n_10 = pow(10, 5);
  int MAX_N = 2 * n_10;

  char s[MAX_N + 1];
  scanf("%s", s);
  //'D'としないとだめ.
  // 前後の関係があるため愚直に数えた方が合理的.

  /*
  int res = 0;
  for(int i=0; i < MAX_N; i++){
      if(s[i] == 'P'){
          if(s[i+1] == 'D' || s[i+1] == '?'){
              res += 2;
          }
      }
      if(s[i] == 'D' || s[i] == '?'){
          res += 1;
      }
  }
  */
  for (int i = 0; i < MAX_N; i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  // return s;
  // char* res = solve();
  printf("%s\\n", s);
  return 0;
}


Error: -11

Fixed submission:

#include <cmath>
#include <iostream>

char *solve() {
  int n_10 = pow(10, 5);
  int MAX_N = 2 * n_10;

  char s[MAX_N + 1];
  scanf("%s", s);
  //'D'としないとだめ.
  // 前後の関係があるため愚直に数えた方が合理的.

  /*
  int res = 0;
  for(int i=0; i < MAX_N; i++){
      if(s[i] == 'P'){
          if(s[i+1] == 'D' || s[i+1] == '?'){
              res += 2;
          }
      }
      if(s[i] == 'D' || s[i] == '?'){
          res += 1;
      }
  }
  */
  for (int i = 0; i < MAX_N; i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }

  return s;
}

int main() {
  char *res = solve();
  printf("%s\\n", res);
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

// myfirstatcoder.cpp : アプリケーションのエントリ ポイントを定義します。

#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, cc, n) for (int i = cc; i < (n); ++i)
#define drep(i, cc, n) for (int i = cc; i > (n); --i)
#define llrep(i, cc, n) for (long long i = cc; i < (n); ++i)
using namespace std;
using ll = long long;

int main() {
  int N;
  string T;
  cin >> T;
  N = T.length();
  if (T.at(0) == '?')
    if (N > 1 && T.at(1) == 'D')
      T.at(0) = 'P';
    else
      T.at(0) = 'D';
  reps(i, 1, N - 1) {
    if (T.at(i) == '?') {
      if (T.at(i - 1) == 'P')
        T.at(i) = 'D';
      else {
        if (T.at(i + 1) == 'D')
          T.at(i) = 'P';
        else
          T.at(i) = 'D';
      }
    }
  }
  if (T.at(N - 1) == '?')
    T.at(N - 1) = 'D';
  cout << T << endl;

  return 0;
}


Error: WA

Fixed submission:

// myfirstatcoder.cpp : アプリケーションのエントリ ポイントを定義します。

#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, cc, n) for (int i = cc; i < (n); ++i)
#define drep(i, cc, n) for (int i = cc; i > (n); --i)
#define llrep(i, cc, n) for (long long i = cc; i < (n); ++i)
using namespace std;
using ll = long long;

int main() {
  int N;
  string T;
  cin >> T;
  N = T.length();
  if (T.at(0) == '?')
    if (T.at(1) == 'D')
      T.at(0) = 'P';
    else
      T.at(0) = 'D';
  if (N > 1) {
    reps(i, 1, N - 1) {
      if (T.at(i) == '?') {
        if (T.at(i - 1) == 'P')
          T.at(i) = 'D';
        else {
          if (T.at(i + 1) == 'D')
            T.at(i) = 'P';
          else
            T.at(i) = 'D';
        }
      }
    }
    if (T.at(N - 1) == '?')
      T.at(N - 1) = 'D';
  }
  cout << T << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string t;
  cin >> t;

  for (int i = t.size() - 1; i >= 0; i--) {
    if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
  }
  cout << t << endl;
  /*
  int score=0;
  int cnt_D=0;
  int cnt_PD=0;
  rep(i,t.size()){
          if (t.at(i)=='D') {
                  cnt_D++;
                  if (i!=0 && t.at(i-1)=='P') {
                          cnt_PD++;
                  }
          }
  }
  score=cnt_D+cnt_PD;
  */

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string t;
  cin >> t;

  rep(i, t.size()) {
    if (t.at(i) == '?') {
      if (i == 0 && t.at(i + 1) == 'D') {
        t.at(i) = 'P';
      } else if (i == 0) {
        t.at(i) = 'D';
      } else if (i == t.size() - 1) {
        t.at(i) = 'D';
      } else if (t.at(i + 1) == 'D') {
        t.at(i) = 'P';
      } else {
        t.at(i) = 'D';
      }
    }
  }
  cout << t << endl;
  /*
  int score=0;
  int cnt_D=0;
  int cnt_PD=0;
  rep(i,t.size()){
          if (t.at(i)=='D') {
                  cnt_D++;
                  if (i!=0 && t.at(i-1)=='P') {
                          cnt_PD++;
                  }
          }
  }
  score=cnt_D+cnt_PD;
  */

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

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

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t.at(i) == '?')
      t.at(i) = 'D';
  }
  cout << t << endl;
}

Error: 0

Fixed submission:

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

int main() {
  string t;
  cin >> t;
  for (long long i = 0; i < t.size(); i++) {
    if (t.at(i) == '?') {
      if (t.at(i - 1) == 'P')
        t.at(i) = 'D';
      else
        t.at(i) = 'P';
    }
  }
  cout << t << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {

  string a, b;
  char c;
  cin >> a;
  int s = a.size();
  int i = 0;
  while (i < s) {
    c = a[i];
    if (c == '?') {
      b += "D";
    } else {
      b += c;
    }
    i++;
  }
  cout << b;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {

  string a, b;
  cin >> a;
  int s = a.size();
  int i = 0;
  while (i < s) {
    if (a[i] == '?') {
      b = b + "D";
    } else {
      b = b + a[i];
    }
    i++;
  }
  cout << b;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
   ~~~~~~~~~~~~~~~~~~~
   \\  |\\/| | |\\ | |  /
   /  |  | | |/ |_|  \\
   ~~~~~~~~~~~~~~~~~~~
*/
#include <iostream>
#include <string.h>
char s[2000200];
using namespace std;
int main() {
  int i;
  cin >> s;
  int x = strlen(s);
  for (i = 0; i < x; i++) {
    if (s[i] == '?') {
      if (s[i - 1] == 'P')
        s[i] = 'D';
      else if (s[i + 1] == 'D')
        s[i] = 'P';
      else
        s[i] = 'D';
    }
  }
  cout << s << endl;
  return 0;
}

Error: TLE

Fixed submission:

/*
   ~~~~~~~~~~~~~~~~~~~
   \\  |\\/| | |\\ | |  /
   /  |  | | |/ |_|  \\
   ~~~~~~~~~~~~~~~~~~~
*/
#include <iostream>
#include <string.h>
char s[200020];
using namespace std;
int main() {
  int i;
  cin >> s;
  for (i = 0; i < strlen(s); i++) {
    if (s[i] == '?') {
      if (s[i - 1] == 'P')
        s[i] = 'D';
      else if (s[i + 1] == 'D')
        s[i] = 'P';
      else
        s[i] = 'D';
    }
  }
  cout << s << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  string s;
  cin >> s;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    if (s[i] == '?')
      s[i] = 'D';
  }
  cout << s << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  string s, ans = "";
  cin >> s;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    ans = ans + s[i];
    if (s[i] == '?')
      ans[i] = 'D';
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int x, int y) { return (x % y == 0 ? y : gcd(y, x % y)); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string T;
  cin >> T;

  string Q = "??";
  long long pos_Q = T.find(Q);
  long long len_Q = Q.length();
  string QQ = "?";
  long long pos_QQ = T.find(QQ);
  long long len_QQ = QQ.length();
  if (pos_Q == 0) {
    T.replace(pos_Q, len_Q, "PD");
  } else if (pos_QQ == 0) {
    T.replace(pos_QQ, len_QQ, "D");
  }

  for (int i = 0; i < T.size(); ++i) {
    if (T.at(i) == '?') {
      if (T.at(i - 1) == 'P')
        T.replace(i, 1, "D");
      else if (i < T.size() - 1 && T.at(i + 1) == 'D')
        T.replace(i, 1, "P");
      else if (i < T.size() - 1 && T.at(i + 1) == '?') {
        T.replace(i, 1, "P");
        T.replace(i + 1, 1, "D");
      } else
        T.replace(i, 1, "D");
    }
  }

  cout << T << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int gcd(int x, int y) { return (x % y == 0 ? y : gcd(y, x % y)); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string T;
  cin >> T;

  string Q = "??";
  auto pos_Q = T.find(Q);
  auto len_Q = Q.length();
  string QQ = "?";
  auto pos_QQ = T.find(QQ);
  auto len_QQ = QQ.length();
  if (pos_Q != std::string::npos) {
    T.replace(pos_Q, len_Q, "PD");
  } else if (pos_QQ != std::string::npos) {
    T.replace(pos_QQ, len_QQ, "D");
  }

  for (int i = 0; i < T.size(); ++i) {
    if (T.at(i) == '?') {
      if (T.at(i - 1) == 'P')
        T.replace(i, 1, "D");
      else if (i < T.size() - 1 && T.at(i + 1) == 'D')
        T.replace(i, 1, "P");
      else if (i < T.size() - 1 && T.at(i + 1) == '?') {
        T.replace(i, 1, "P");
        T.replace(i + 1, 1, "D");
      } else
        T.replace(i, 1, "D");
    }
  }

  cout << T << endl;

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

// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i > 0; --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX = 100;
const int INF = (1 << 12);

int main() {
  string s;
  cin >> s;
  char p, n;
  if (s.size() == 1) {
    if (s[0] == '?')
      s[0] = 'D';
    cout << s << endl;
    return 0;
  }
  rep(i, s.size() - 1) {
    p = s[i];
    n = s[i + 1];
    if (p == '?') {
      if (n == '?') {
        s[i] = 'D';
        s[i + 1] = 'D';
        i++;
      } else if (n == 'P') {
        s[i] = 'D';
      } else if (n == 'D') {
        s[i] = 'P';
      }
    } else if (p == 'P' || p == 'D') {
      if (n == '?') {
        s[i + 1] = 'D';
      }
    }
  }
  cout << s << endl;
  return 0;
}

Error: 0

Fixed submission:

// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i > 0; --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX = 100;
const int INF = (1 << 12);

int main() {
  string s;
  cin >> s;
  char p, m, n;
  if (s[0] == '?')
    s[0] = 'P';
  rep(i, s.size() - 2) {
    p = s[i];
    m = s[i + 1];
    n = s[i + 2];
    if (p == 'P') {
      if (m == '?')
        s[i + 1] = 'D';
    } else if (p == 'D') {
      if (m == '?') {
        if (n == '?')
          s[i + 1] = 'P';
        else if (n == 'P')
          s[i + 1] = 'D';
        else
          s[i + 1] = 'P';
      }
    }
  }
  if (s[s.size() - 1] == '?')
    s[s.size() - 1] = 'D';
  cout << s << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string T;
  int A;
  cin >> T;
  A = T.size();
  if (A != 1) {
    if (T.at(0) == '?') {
      if (T.at(1) == '?' || T.at(1) == 'D')
        T.at(0) = 'P';
    }
    if (T.at(0) == '?' && T.at(1) == 'P')
      T.at(0) = 'D';
    for (int i = 1; i < A - 1; i++) {
      if (T.at(i) == '?' && T.at(i - 1) == 'P')
        T.at(i) = 'D';
      if (T.at(i) == '?') {
        if (T.at(i + 1) == 'D' || T.at(i + 1) == '?')
          T.at(i) = 'P';
      }
      if (T.at(i) == '?' && T.at(i + 1) == 'P')
        T.at(i) = 'D';
    }
    if (T.at(A - 1) == '?')
      T.at(A - 1) = 'D';
  }
  if (A == 1)
    T.at(0) = 'D';
  cout << T << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string T;
  int A;
  cin >> T;
  A = T.size();
  if (T.at(0) == '?') {
    if (T.at(1) == '?' || T.at(1) == 'D')
      T.at(0) = 'P';
  }
  if (T.at(0) == '?' && T.at(1) == 'P')
    T.at(0) = 'D';
  for (int i = 1; i < A - 1; i++) {
    if (T.at(i) == '?' && T.at(i - 1) == 'P')
      T.at(i) = 'D';
    if (T.at(i) == '?') {
      if (T.at(i + 1) == 'D' || T.at(i + 1) == '?')
        T.at(i) = 'P';
    }
    if (T.at(i) == '?' && T.at(i + 1) == 'P')
      T.at(i) = 'D';
  }
  if (T.at(A - 1) == '?')
    T.at(A - 1) = 'D';
  cout << T << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string T;
  cin >> T;

  if (T.size() == 1) {
    if (T.at(0) == '?') {
      T.at(0) = 'D';
    }
  }

  if (T.size() > 1) {
    if (T.at(0) == '?') {
      if (T.at(1) == 'P') {
        T.at(0) = 'D';
      } else {
        T.at(0) = 'P';
      }
    }

    if (T.at(T.size() - 1) == '?') {
      T.at(T.size() - 1) = 'D';
    }

    for (int i = 1; i < T.size(); i++) {
      if (T.at(i) == '?') {
        if (T.at(i - 1) == 'P') {
          T.at(i) = 'D';
        } else if (T.at(i + 1) == 'P') {
          T.at(i) = 'D';
        } else {
          T.at(i) = 'P';
        }
      }
    }
  }
  cout << T << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string T;
  cin >> T;

  if (T.at(0) == '?') {
    if (T.at(1) == 'P') {
      T.at(0) = 'D';
    } else {
      T.at(0) = 'P';
    }
  }

  if (T.at(T.size() - 1) == '?') {
    T.at(T.size() - 1) = 'D';
  }

  for (int i = 1; i < T.size(); i++) {
    if (T.at(i) == '?') {
      if (T.at(i - 0) == 'P') {
        T.at(i) = 'D';
      } else if (T.at(i + 1) == 'P') {
        T.at(i) = 'D';
      } else {
        T.at(i) = 'P';
      }
    }
  }

  cout << T << endl;

  return 0;
}