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

#include <iostream>
#include <string>

using namespace std;

int main() {
  string s1, s2;
  cin >> s1 >> s2;

  for (auto i = s1.begin(); i != s1.end(); ++i) {
    auto j = s2.begin();
    auto k = i;
    while (j != s2.end() && k != s1.end()) {
      if (*k != *j) {
        break;
      }
      ++k;
      ++j;
    }
    if (j == s2.end()) {
      cout << distance(s1.begin(), i) << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string s1, s2;
  cin >> s1 >> s2;

  for (auto i = s1.begin(); i != s1.end() - s2.size() + 1; ++i) {
    auto m = true;
    auto k = i;
    for (auto j = s2.begin(); j != s2.end(); ++j) {
      if (*k++ != *j) {
        m = false;
        break;
      }
    }
    if (m) {
      cout << distance(s1.begin(), i) << endl;
    }
  }

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

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

int main() {
  string a, b;
  cin >> a >> b;
  for (int i = 0; i <= a.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      if (i + j >= a.size() || a[i + j] != b[j])
        break;
      if (j + 1 == b.size())
        cout << i << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string a, b;
  cin >> a >> b;

  for (int i = 0; i <= a.size() - b.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      if (a[i + j] != b[j])
        break;
      if (j + 1 == b.size())
        cout << i << endl;
    }
  }

  return 0;
}
Problem p02247 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int i, j, k, c;
  string T, P;

  cin >> T;
  cin >> P;
  if (T.size() >= P.size()) {
    for (i = 0; i <= T.size() - P.size(); i++) {
      j = i;
      k = 0;
      c = 0;
      while (j <= T.size() - 1 && T[j] == P[k]) {
        c++;
        k++;
        j++;
      }
      if (c == P.size())
        cout << i << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int i, j, k, c;
  string T, P;

  cin >> T;
  cin >> P;
  for (i = 0; i <= T.size() - P.size(); i++) {
    j = i;
    k = 0;
    c = 0;
    while (j <= T.size() - 1 && T[j] == P[k]) {
      c++;
      k++;
      j++;
    }
    if (c == P.size())
      cout << i << endl;
  }
  return 0;
}
Problem p02247 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string t, p;
  int fin;
  cin >> t >> p;
  fin = t.length() - p.length() + 1;
  if (fin <= 0)
    return 0;
  for (int i = 0; i < fin; i++) {
    bool flag = 1;
    for (int j = 0; j < p.length(); j++) {
      if (t[i + j] != p[j]) {
        flag = 0;
        break;
      }
    }
    if (flag)
      cout << i << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string t, p;
  cin >> t >> p;
  int fin = t.length() - p.length() + 1;
  if (fin <= 0)
    return 0;
  for (int i = 0; fin; i++) {
    bool flag = 1;
    for (int j = 0; j < p.length(); j++) {
      if (t[i + j] != p[j]) {
        flag = 0;
        break;
      }
    }
    if (flag)
      cout << i << endl;
  }

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

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

int main() {
  string T, P;

  cin >> T;
  cin >> P;

  if (T.length() >= P.length())
    for (int i = 0; i <= T.length() - P.length(); i++)
      if (T.substr(i, P.length()) == P)
        cout << i << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string T, P;

  cin >> T;
  cin >> P;

  for (int i = 0; i <= T.length() - P.length(); i++)
    if (T.substr(i, P.length()) == P)
      cout << i << endl;

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

#include <iostream>
#include <string>

using namespace std;

int main() {
  string S, T;

  cin >> S >> T;

  if (S.size() >= T.size()) {
    for (int i = 0; i <= S.size() - T.size(); i++) {
      if (T == S.substr(i, T.size())) {
        cout << i << endl;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string S, T;

  cin >> S >> T;

  for (int i = 0; i <= S.size() - T.size(); i++) {
    if (T == S.substr(i, T.size())) {
      cout << i << endl;
    }
  }

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

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

string s, t;

int main() {
  cin >> s >> t;
  if (s.size() < t.size()) {
    return 0;
  }
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j]) {
        break;
      }
      if (j == t.size() - 1 && s[i + j] == t[j]) {
        cout << i << endl;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

string s, t;

int main() {
  cin >> s >> t;
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j]) {
        break;
      }
      if (j == t.size() - 1 && s[i + j] == t[j]) {
        cout << i << endl;
      }
    }
  }
  return 0;
}
Problem p02247 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

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

int main(void) {
  string t;
  string p;
  cin >> t;
  cin >> p;
  rep(i, (int)t.size() - (int)p.size() + 1) {
    rep(j, p.size()) {
      if (i + j >= t.size() || t[i + j] != p[j])
        break;
      ;
      if (j == p.size() - 1) {
        cout << i << endl;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

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

int main(void) {
  string t;
  string p;
  cin >> t;
  cin >> p;
  rep(i, t.size() - p.size() + 1) {
    rep(j, p.size()) {
      if (i + j >= t.size() || t[i + j] != p[j])
        break;
      ;
      if (j == p.size() - 1) {
        cout << i << endl;
      }
    }
  }

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

#include <iostream>

int main() {
  std::ios_base::sync_with_stdio(false);

  std::string a;
  std::string b;

  std::cin >> a;
  std::cin >> b;

  bool match = false;

  if (a.size() < b.size()) {
    return 0;
  }

  for (int i = 0; i <= (a.size() - b.size()); i++) {
    match = true;

    for (int j = 0; j < b.size(); j++) {
      if (a[i + j] != b[j]) {
        match = false;

        break;
      }
    }

    if (match) {
      std::cout << i << std::endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

int main() {
  std::ios_base::sync_with_stdio(false);

  std::string a;
  std::string b;

  std::cin >> a;
  std::cin >> b;

  bool match = false;

  for (int i = 0; i <= (a.size() - b.size()); i++) {
    match = true;

    for (int j = 0; j < b.size(); j++) {
      if (a[i + j] != b[j]) {
        match = false;

        break;
      }
    }

    if (match) {
      std::cout << i << std::endl;
    }
  }

  return 0;
}
Problem p02247 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MAX 1000 + 1
#define ASCII 123

char text[MAX];
char pat[MAX];
int skip[ASCII];

int main() {
  int i, textLen, patLen, pLast, pText, pPat;
  cin >> text;
  cin >> pat;

  textLen = strlen(text);
  patLen = strlen(pat);

  for (i = 0; i < ASCII; i++)
    skip[i] = patLen;

  for (i = 0; i < patLen - 1; i++)
    skip[int(pat[i])] = patLen - i - 1;

  pLast = patLen - 1;
  while (pLast < textLen) {
    pText = pLast;
    pPat = patLen - 1;
    while (text[pText] == pat[pPat]) {
      if (pPat == 0) {
        cout << pText << endl;
        break;
      }
      pText--;
      pPat--;
    }
    pLast = pLast + skip[int(text[pLast])];
  }

  return 0;
}


Error: TLE

Fixed submission:

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

#define MAX 1000 + 1
#define ASCII 123

char text[MAX];
char pat[MAX];
int skip[ASCII];

int main() {
  int i, textLen, patLen, pLast, pText, pPat;
  cin >> text;
  cin >> pat;

  textLen = strlen(text);
  patLen = strlen(pat) - 1;

  for (i = 0; i < ASCII; i++)
    skip[i] = patLen;

  for (i = 0; i < patLen; i++)
    skip[int(pat[i])] = patLen - i;

  pLast = patLen;
  while (pLast < textLen) {
    pText = pLast;
    pPat = patLen;
    while (text[pText] == pat[pPat]) {
      if (pPat == 0) {
        cout << pText << endl;
        break;
      }
      pText--;
      pPat--;
    }
    pLast = pLast + skip[int(text[pLast])];
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  string s, t;

  cin >> s >> t;
  long k = 0;
  k = t.size();
  long p = 0;
  p = s.size();

  for (long i = 0; i < p - k + 1; i++) {
    if (s.substr(i, k) == t) {
      cout << i << endl;
    }
  }
}


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


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  string s, c;

  cin >> s >> c;

  for (long i = 0; i < 1000; i++) {
    for (long j = 0; j < 1000; j++) {
      if (s.substr(i, j) == c) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p02247 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  int count = 0;
  vector<int> index;
  string a, b;
  cin >> a >> b;
  if (a.size() < b.size())
    return 0;
  for (int i = 0; i <= a.size() - b.size(); i++) {
    if (a.substr(i, b.size()) == b) {
      count++;
      index.push_back(i);
    }
  }
  if (count != 0) {
    for (int i : index)
      cout << i << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  int count = 0;
  vector<int> index;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i <= a.size() - b.size(); i++) {
    if (a.substr(i, b.size()) == b) {
      count++;
      index.push_back(i);
    }
  }
  if (count != 0) {
    for (int i : index)
      cout << i << endl;
  }
}
Problem p02247 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void brute_force(string T, string P) {
  const char *Tc = T.c_str();
  const char *Pc = P.c_str();
  int i, j;
  for (i = 0; i < (int)T.length() - (int)P.length() + 1; i++) {
    for (j = 0; j < P.length(); j++) {
      if (Tc[i + j] != Pc[j])
        break;
      if (j == P.length() - 1)
        cout << i << endl;
    }
  }
}

int main() {
  string T, P;
  cin >> T >> P;
  brute_force(T, P);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void brute_force(string T, string P) {
  const char *Tc = T.c_str();
  const char *Pc = P.c_str();
  int i, j;
  for (i = 0; i < T.length() - P.length() + 1; i++) {
    for (j = 0; j < P.length(); j++) {
      if (Tc[i + j] != Pc[j])
        break;
      if (j == P.length() - 1)
        cout << i << endl;
    }
  }
}

int main() {
  string T, P;
  cin >> T >> P;
  brute_force(T, P);
  return 0;
}
Problem p02247 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int dx[62], Tlen, Plen;
string T, P;

int suffix(char c) {
  if ('0' <= c && c <= '9') {
    return (c - 48);
  } else if ('a' <= c && c <= 'z') {
    return (c - 87);
  } else if ('A' <= c && c <= 'Z') {
    return (c - 29);
  }
}

void init() {
  Tlen = T.size();
  Plen = P.size();
  for (int i = 0; i < 62; i++)
    dx[i] = -1;
  for (int i = Plen - 2, v = 1; i >= 0; i--, v++) {
    if (dx[suffix(P[i])] == -1) {
      dx[suffix(P[i])] = v;
    }
  }
  for (int i = 0; i < 62; i++) {
    if (dx[i] == -1) {
      dx[i] = Plen;
    }
  }
}

int main() {
  cin >> T >> P;
  init();

  int pos = Plen - 1;
  while (pos < Tlen) {
    for (int i = 0; i < Plen; i++) {
      if (T[pos - i] != P[Plen - i - 1]) {
        pos = (pos - i) + max(dx[suffix(T[pos - i])], i + 1);
        break;
      }
      if (i == Plen - 1) {
        cout << pos - i << endl;
        pos++;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int dx[62], Tlen, Plen;
string T, P;

int suffix(char c) {
  if ('0' <= c && c <= '9') {
    return (c - 48);
  } else if ('a' <= c && c <= 'z') {
    return (c - 87);
  } else if ('A' <= c && c <= 'Z') {
    return (c - 29);
  }
}

void init() {
  Tlen = T.size();
  Plen = P.size();
  for (int i = 0; i < 62; i++)
    dx[i] = -1;
  dx[suffix(P[Plen - 1])] = Plen;
  for (int i = Plen - 2, v = 1; i >= 0; i--, v++) {
    if (dx[suffix(P[i])] == -1) {
      dx[suffix(P[i])] = v;
    }
  }
  for (int i = 0; i < 62; i++) {
    if (dx[i] == -1) {
      dx[i] = Plen;
    }
  }
}

int main() {
  cin >> T >> P;
  init();

  int pos = Plen - 1;
  while (pos < Tlen) {
    for (int i = 0; i < Plen; i++) {
      if (T[pos - i] != P[Plen - i - 1]) {
        pos = (pos - i) + max(dx[suffix(T[pos - i])], i);
        break;
      }
      if (i == Plen - 1) {
        cout << pos - i << endl;
        pos++;
      }
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

struct RollingHash {
  typedef long long int_type;
  typedef pair<int_type, int_type> hash_type;

  int_type base, mod[2];

  vector<int_type> hashed[2], power[2];

  RollingHash() { base = 9973LL, mod[0] = 999999937LL, mod[1] = 1000000007LL; }

  void init(const string &s) {
    int sz = s.size();

    for (int i = 0; i < 2; i++) {
      hashed[i].assign(sz + 1, 0);
      power[i].assign(sz + 1, 0);

      hashed[i][0] = 0;
      power[i][0] = 1;
      for (int j = 0; j < sz; j++) {
        power[i][j + 1] = power[i][j] * base % mod[i];
        hashed[i][j + 1] = (hashed[i][j] + s[j]) * base % mod[i];
      }
    }
  }

  hash_type get(int l, int r) {
    int_type hash1 =
        ((hashed[0][r] - hashed[0][l] * power[0][r - l]) % mod[0] + mod[0]) %
        mod[0];
    int_type hash2 =
        ((hashed[1][r] - hashed[1][l] * power[1][r - l]) % mod[1] + mod[1]) %
        mod[1];
    return hash_type(hash1, hash2);
  }

  hash_type concat(hash_type hash1, hash_type hash2, int hash2_len) {
    return hash_type((hash1.first * power[0][hash2_len] + hash2.first) % mod[0],
                     (hash1.second * power[1][hash2_len] + hash2.second) %
                         mod[1]);
  }
};

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

  RollingHash rollhash[2];
  rollhash[0].init(T);
  rollhash[1].init(P);

  for (int i = 0; i <= (int)(T.size() - P.size()); i++) {
    if (rollhash[0].get(i, i + P.size()) == rollhash[1].get(0, P.size()))
      cout << i << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

struct RollingHash {
  typedef long long int_type;
  typedef pair<int_type, int_type> hash_type;

  int_type base, mod[2];

  vector<int_type> hashed[2], power[2];

  RollingHash() { base = 9973LL, mod[0] = 999999937LL, mod[1] = 1000000007LL; }

  void init(const string &s) {
    int sz = s.size();

    for (int i = 0; i < 2; i++) {
      hashed[i].assign(sz + 1, 0);
      power[i].assign(sz + 1, 0);

      hashed[i][0] = 0;
      power[i][0] = 1;
      for (int j = 0; j < sz; j++) {
        power[i][j + 1] = power[i][j] * base % mod[i];
        hashed[i][j + 1] = (hashed[i][j] + s[j]) * base % mod[i];
      }
    }
  }

  hash_type get(int l, int r) {
    int_type hash1 =
        ((hashed[0][r] - hashed[0][l] * power[0][r - l]) % mod[0] + mod[0]) %
        mod[0];
    int_type hash2 =
        ((hashed[1][r] - hashed[1][l] * power[1][r - l]) % mod[1] + mod[1]) %
        mod[1];
    return hash_type(hash1, hash2);
  }

  hash_type concat(hash_type hash1, hash_type hash2, int hash2_len) {
    return hash_type((hash1.first * power[0][hash2_len] + hash2.first) % mod[0],
                     (hash1.second * power[1][hash2_len] + hash2.second) %
                         mod[1]);
  }
};

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

  RollingHash rollhash[2];
  rollhash[0].init(T);
  rollhash[1].init(P);

  for (int i = 0; i <= T.size() - P.size(); i++) {
    if (rollhash[0].get(i, i + P.size()) == rollhash[1].get(0, P.size()))
      cout << i << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  string t, p;
  cin >> t >> p;
  if (t.size() >= p.size())
    for (int i = 0; i < t.size() - p.size() + 1; i++) {
      int f = 0;
      for (int j = 0; j < p.size(); j++)
        if (t[i + j] != p[j])
          f = 1;
      if (f)
        continue;
      cout << i << endl;
    }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string t, p;
  cin >> t >> p;
  for (int i = 0; i < t.size() - p.size() + 1; i++) {
    int f = 0;
    for (int j = 0; j < p.size(); j++)
      if (t[i + j] != p[j])
        f = 1;
    if (f)
      continue;
    cout << i << endl;
  }
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define N 950527
using namespace std;
typedef unsigned long long ull;
int main() {
  string s, p;
  cin >> s >> p;
  ull a = 0, b = 0, g = 1;
  for (int i = 0; i < p.size(); i++)
    b *= N, b += s[i], g *= N;
  for (int i = 0; i < p.size(); i++)
    a *= N, a += p[i];
  if (b == a)
    printf("0\\n");

  for (int i = p.size(); i < (int)s.size(); i++) {
    b *= N, b += s[i], b -= s[i - p.size()] * g;
    if (b == a)
      printf("%d\\n", i - p.size() + 1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, p;
  cin >> s >> p;
  for (int i = 0; i < s.size(); i++)
    for (int j = 0; j < p.size(); j++) {
      if (i + j >= s.size())
        break;
      if (s[i + j] != p[j])
        break;
      if (j == p.size() - 1)
        cout << i << endl;
    }
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <ios>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<int> match_KMP(string &T, string &P);
vector<int> preprocess_KMP(string &P);

int main() {
  ios::sync_with_stdio(false);
  string T;
  string P;
  cin >> T;
  cin >> P;
  auto result = match_KMP(T, P);
  for (auto pos : result)
    cout << pos << '\\n';
  return 0;
}

vector<int> match_KMP(string &T, string &P) {
  int n = T.size();
  int m = P.size();
  auto pi = preprocess_KMP(P);
  vector<int> result;
  int q = 0;
  for (int i = 0; i != n; ++i) {
    while (q > 0 and T[i] != P[q]) {
      q = pi[q];
    }
    if (T[i] == P[q])
      ++q;
    if (q == m) {
      result.push_back(i - m + 1);
      q = pi[q];
    }
  }
  return result;
}

vector<int> preprocess_KMP(string &P) {
  int m = P.size();
  vector<int> pi(m + 1, 0);
  int k = 0;
  for (int q = 1; q != m; ++q) {
    while (k > 0 and P[q] != P[k]) {
      k = pi[k];
    }
    if (P[q] == P[k])
      ++k;
    pi[q + 1] = k;
  }
  return pi;
}

Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  string T;
  string P;
  cin >> T;
  cin >> P;
  size_t pos = T.find(P, 0);
  while (pos != string::npos) {
    cout << pos << endl;
    pos = T.find(P, pos + 1);
  }
  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  string S, T;

  cin >> S >> T;

  if (S.size() >= T.size()) {
    for (int i = 0; i <= S.size() - T.size(); i++) {
      if (T[0] == S[i]) {
        if (T == S.substr(i, T.size())) {
          printf("%d\\n", i);
        }
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <string>

using namespace std;

int main() {
  string S, T;

  cin >> S >> T;

  if (S.size() >= T.size()) {
    list<char> que;

    for (int i = 0; i < T.size() - 1; i++) {
      que.push_back(S[i]);
    }

    for (int i = 0; i <= S.size() - T.size(); i++) {
      que.push_back(S[i + T.size() - 1]);

      list<char>::iterator it = que.begin();

      int ptr = 0;

      while (it != que.end()) {
        if (*it != T[ptr]) {
          goto Exit;
        }

        ptr++;

        it++;
      }

      cout << i << endl;

    Exit:;

      que.pop_front();
    }
  }

  return 0;
}
Problem p02248 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string T, P;

  cin >> T >> P;

  uint64_t ht = 0, hp = 0, b = 1;
  for (uint32_t i = 0; i < P.length(); i++) {
    ht = (ht << 7) + T[i];
    hp = (hp << 7) + P[i];
    b = b << 7;
  }

  for (int32_t i = 0; i <= (int32_t)(T.length() - P.length()); i++) {
    if (ht == hp)
      if (T.substr(i, P.length()) == P)
        printf("%d\\n", i);
    ht = (ht << 7) + T[i + P.length()] - b * T[i];
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string T, P;

  cin >> T >> P;

  unordered_map<uint8_t, int32_t> bch;
  for (uint32_t i = 0; i < P.length() - 1; i++)
    bch[P[i]] = P.length() - i - 1;

  int32_t i = 0;
  while (i <= (int32_t)(T.length() - P.length())) {
    int32_t j = P.length() - 1;

    while (j >= 0 && T[i + j] == P[j])
      j--;

    if (j < 0) {
      printf("%d\\n", i++);
    } else {
      auto itr = bch.find(T[max(i + j, i)]);
      if (itr != bch.end()) {
        i += max(itr->second + j - (int32_t)P.length() + 1, 1);
      } else {
        i += j + 1;
      }
    }
  }

  return 0;
}