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

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string S, T;
  cin >> S;
  cin >> T;

  int n = S.size() - T.size() + 1;
  vector<int> a(n);

  for (int i = 0; i < n; i++) {
    a[i] = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S[j + i] != T[j]) {
        a[i]++;
      }
    }
  }

  int min = a[0];
  for (int i = 1; i < n; i++) {
    if (min > a[i]) {
      min = a[i];
    }
  }

  cout << min << endl;
}

Error: -11

Fixed submission:

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

  string S, T;
  cin >> S;
  cin >> T;

  int n = S.size() - T.size() + 1;
  vector<int> a;

  for (int i = 0; i < n; i++) {
    a[i] = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S[j + i] != T[j]) {
        a[i]++;
      }
    }

    int min = a[0];
    for (i = 1; i < n; i++) {
      if (min > a[i]) {
        min = a[i];
      }
    }

    cout << min << endl;
  }
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string b, t;
  cin >> b >> t;
  int ct = 0;
  int minct = t.size();
  for (int i = 0; i < (int)b.size(); i++) {
    if (i + (int)t.size() > (int)b.size())
      break;
    for (int j = 0; j < (int)t.size(); j++) {
      if (b.at(i + j) != t.at(j)) {
        ct++;
      }
    }
    minct = min(minct, ct);
    ct = 0;
  }
  cout << minct;
}

Error: WA

Fixed submission:

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

int main() {
  string b, t;
  cin >> b >> t;
  int ct = 0;
  int minct = t.size();
  for (int i = 0; i < (int)b.size(); i++) {
    if (b.at(i) != t.at(0))
      continue;
    for (int j = 0; j < (int)t.size(); j++) {
      if (b.at(i + j) != t.at(j)) {
        ct++;
      }
    }
    minct = min(minct, ct);
    ct = 0;
  }
  cout << minct;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ft first
#define sd second
#define ll long long
#define pb push_back
#define mkp make_pair
#define pll pair<ll, ll>
#define vll vector<int>
#define mll map<ll, ll>
#define pqg priority_queue<ll>
#define pqs priority_queue<ll, vll, greater<ll>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define MAXN 10000001
void online_judge() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}

void ISO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main() {

  ISO();
  online_judge();
  string s, t;
  cin >> s >> t;
  int n = s.length();
  int k = t.length();
  if (n == 1) {
    (s[0] == t[0]) ? (cout << 0 << "\\n") : (cout << 1 << "\\n");
    return 0;
  } else if (n == k) {
    int cost = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] != t[i]) {
        cost++;
      }
    }
    cout << cost << "\\n";
    return 0;
  }
  vector<int> ans;
  for (int i = 0; i < (n - k); ++i) {
    ll cost = 0;
    for (int j = i; j < i + k; ++j) {
      if (s[j] == t[j - i]) {
        continue;
      } else {
        cost++;
      }
    }
    ans.push_back(cost);
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << "\\n";

  // cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ft first
#define sd second
#define ll long long
#define pb push_back
#define mkp make_pair
#define pll pair<ll, ll>
#define vll vector<int>
#define mll map<ll, ll>
#define pqg priority_queue<ll>
#define pqs priority_queue<ll, vll, greater<ll>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define MAXN 10000001
void online_judge() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}

void ISO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main() {

  ISO();
  // online_judge();
  string s, t;
  cin >> s >> t;
  int n = s.length();
  int k = t.length();
  if (n == 1) {
    (s[0] == t[0]) ? (cout << 0 << "\\n") : (cout << 1 << "\\n");
    return 0;
  }
  vector<int> ans;
  for (int i = 0; i < (n - k); ++i) {
    ll cost = 0;
    for (int j = i; j < i + k; ++j) {
      if (s[j] == t[j - i]) {
        continue;
      } else {
        cost++;
      }
    }
    ans.push_back(cost);
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << "\\n";

  // cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  string S, T;
  cin >> S >> T;
  int N, M;
  N = S.size();
  M = T.size();
  vector<int> vec(N);

  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < M; j++) {
      if (T.at(j) == S.at(j + i))
        vec.at(i)++;
    }
  }

  sort(vec.begin(), vec.end());

  cout << M - vec.at(N - 1) << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

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

int main() {

  string S, T;
  cin >> S >> T;
  int N, M;
  N = S.size();
  M = T.size();
  vector<int> vec(M);

  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < M; j++) {
      if (T.at(j) == S.at(j + i))
        vec.at(i)++;
    }
  }

  sort(vec.begin(), vec.end());

  cout << M - vec.at(M - 1) << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

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

  int ans = t.size();
  bool x = true;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    int count = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j]) {
        count++;
      }
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int a = 0, ans = 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]) {
        a++;
      }
    }
    if (i == 0) {
      ans = a;
    } else if (a < ans) {
      ans = a;
    }
    a = 0;
  }
  cout << ans << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

// 全探索
int main() {
  string S, T;
  cin >> S >> T;
  int ans;
  priority_queue<int> X;
  int l = S.size();
  int L = T.size();
  /*for(int i=0;i<=ans;i++){
    string X=T.substr(i,L-ans);
    for(int j=0;j<l+ans-L;j++){
      if(S.substr(j,L-ans)==X) goto Fin;
    }
  }
  ans++;*/
  for (int i = 0; i <= l - L; i++) {
    ans = 0;
    for (int j = 0; j < L; j++) {
      if (S.at(i + j) == T.at(j))
        ans++;
    }
    X.push(ans);
  }
  /* if(l==L){
     ans=0;
     for(int i=0;i<L;i++){
       if(S.at(i)==T.at(i)) ans++;
     }
     X.push(ans);
   }*/
  cout << L - X.top() << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

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

// 全探索
int main() {
  string S, T;
  cin >> S >> T;
  int ans;
  priority_queue<int> X;
  int l = S.size();
  int L = T.size();
  /*for(int i=0;i<=ans;i++){
    string X=T.substr(i,L-ans);
    for(int j=0;j<l+ans-L;j++){
      if(S.substr(j,L-ans)==X) goto Fin;
    }
  }
  ans++;*/
  for (int i = 0; i <= l - L; i++) {
    ans = 0;
    for (int j = 0; j <= L; j++) {
      if (S.at(i + j) == T.at(j))
        ans++;
    }
    X.push(ans);
  }

  cout << L - X.top() << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

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

  int ans = t.size();

  for (int start = 0; start <= s.size() - t.size(); start++) {
    int diff = 0;
    for (int i = 0; i < t.size(); i++) {
      if (t[i] != s[start + i]) {
        diff++;
      }
    }
    ans = min(ans, diff);
  }

  cout << ans << endl;
  return 0;
}


Error: -11

Fixed submission:

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

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

  int ans = t.size();

  for (int start = 0; start <= s.size() - t.size(); start++) {
    int diff = 0;
    for (int i = 0; i < t.size(); i++) {
      if (t[i] != s[start + i]) {
        diff++;
      }
    }
    ans = min(ans, diff);
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T;
  int i, j, k, count, max = 0;
  cin >> S >> T;
  for (i = 0; i < (int)T.size(); i++) {
    for (j = 0 + i; j < (int)S.size() - (int)T.size() + i + 1; j++) {
      if (T.at(i) == S.at(j)) {
        count = 0;
        count++;
        for (k = 1; (k < (int)T.size() - i) && (k < (int)S.size() - j); k++) {
          if (T.at(i + k) == S.at(j + k)) {
            count++;
          }
        }
        if (count > max) {
          max = count;
        }
      }
    }
  }
  cout << T.size() - max << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T;
  int i, j, k, count = 0, max = 0;
  cin >> S >> T;
  for (i = 0; i < T.size(); i++) {
    for (j = 0 + i; j < S.size(); j++) {
      if (T.at(i) == S.at(j)) {
        count = 0;
        count++;
        for (k = 1; k < T.size() - i; k++) {
          if (T.at(i + k) == S.at(j + k)) {
            count++;
          } else {
            break;
          }
        }
        if (count > max) {
          max = count;
        }
      }
    }
  }
  cout << T.size() - max << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

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

  const char *cS = S.c_str();
  const char *cT = T.c_str();

  int max_count = 0;
  for (size_t i = 0; i < (S.size() - T.size() + 1); ++i) {
    int count = 0;
    for (size_t j = 0; j < T.size(); ++j) {
      if (cS[i + j] == cT[j]) {
        ++count;
      }
    }

    if (max_count < count) {
      max_count = count;
    }
  }

  cout << (static_cast<int>(T.size()) - max_count) << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

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

  const char *cS = S.c_str();
  const char *cT = T.c_str();

  int max_count = 0;
  for (size_t i = 0; i < (S.size() - T.size() - 1); ++i) {
    int count = 0;
    for (size_t j = 0; j < T.size(); ++j) {
      if (cS[i + j] == cT[j]) {
        ++count;
      }
    }

    if (max_count < count) {
      max_count = count;
    }
  }

  cout << (static_cast<int>(T.size()) - max_count) << endl;

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

#include <iostream>
using namespace std;
int main() {
  char a[1001], b[1001];
  long least, var, lena = 0, lenb = 0, l = 1;
  cin >> a >> b;
  for (; b[lenb]; lenb++)
    ;
  for (; a[lena]; lena++)
    ;
  for (int i = 0; i <= lena - lenb; i++) {
    var = 0;
    for (int j = 0; j < lenb; j++) {
      if (a[i + j] != b[j]) {
        var++;
      }
    }

    if (var < least || l)
      least = var;
    if (l)
      l = 0;
  }
  cout << least;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
string s, t;
int a[30] = {0};
int sum = 0;
int dfs(int x, int y) {
  for (int i = 1; i + y < t.size(); i++) {
    if (s[x + i] == t[y + i])
      sum++;
  }
}
int main() {

  cin >> s >> t;
  int len1, len2;
  len1 = s.size();
  len2 = t.size();
  int ans = len2;
  for (int j = 0; j < len2; j++)
    a[t[j] - 'a'] = 1;
  for (int i = 0; i < len1; i++) {

    if (a[s[i] - 'a'] == 1) {
      if (len2 > i) {
        for (int j = 0; j <= i; j++) {
          if (len1 - i - 1 < len2 - j - 1)
            break;
          if (s[i] == t[j]) {
            sum++;
            dfs(i, j);
            ans = min(ans, len2 - sum);
            sum = 0;
          }
        }
      } else {
        for (int j = 0; j < len2; j++) {
          if (len1 - i - 1 < len2 - j - 1)
            j = len2 - (len1 - i);
          if (s[i] == t[j]) {
            sum++;
            dfs(i, j);
            ans = min(ans, len2 - sum);
            sum = 0;
          }
        }
      }
    }
  }
  cout << ans;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

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

  int L = S.size();
  int l = T.size();

  int ans = l;

  for (int i = 0; i <= L - l; i++) {
    int count = 0;
    for (int j = 0; j < l; j++) {
      if (S.at(i + j) != T.at(j)) {
        count++;
      }
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

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

  int L = S.size();
  int l = T.size();

  int count = 0;
  int j = 0;

  for (int i = 0; i < L - l; i++) {
    if (S.at(i) == T.at(0)) {
      while (true) {
        if (S.at(i + j) == T.at(j)) {
          count++;
          j++;
        } else {
          break;
        }
      }
      int z = count;
      cout << l - z << endl;

    } else {
      // cout << l-1 <<endl;
    }
  }
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long ara[101], sum[101];

int main() {
  int a, b, c, d, i, j, ans = 999999, k;
  string s, s1;
  cin >> s >> s1;
  int mid = s.size() - s1.size();
  for (i = 0; i <= mid; i++) {
    c = 0;
    for (j = i, k = 0; k < s1.size(); j++, k++) {
      if (s[j] != s1[k])
        c++;
    }
    ans = min(ans, c);
  }
  cout << ans << "\\n";

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long ara[101], sum[101];

int main() {
  int a, b, c, d, i, j, ans = 999999, k;
  string s, s1;
  cin >> s >> s1;

  for (i = 0; i < s.size() - s1.size() - 1; i++) {
    c = 0;
    for (j = i, k = 0; k < s1.size(), j < j + s1.size(); j++, k++) {
      if (s[j] != s1[k])
        c++;
    }
    ans = min(ans, c);
  }
  cout << ans << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid ((l + r) / 2)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (int i = (a); i >= (b); --i)
#define file(a) freopen(#a ".in", "r", stdin), freopen(#a ".out", "w", stdout);
const int maxn = 1e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int n, m, Q, K, T;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
char a[maxn], b[maxn];
signed main() {
  // file(a);
  scanf("%s%s", a, b);
  int ans = 0;
  // cout<<strlen(a)<<" "<<strlen(b)<<endl;
  rep(i, 0, strlen(a) - 1) {
    int sum = 0;
    if (i + strlen(b) - 1 > strlen(a) - 1)
      break;
    rep(j, 0, strlen(b) - 1) {
      if (a[i + j] == b[j])
        ++sum;
    }
    ans = max(ans, sum);
  }
  printf("%d\\n", strlen(b) - ans);

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l + r) / 2)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (int i = (a); i >= (b); --i)
#define file(a) freopen(#a ".in", "r", stdin), freopen(#a ".out", "w", stdout);
const int maxn = 2e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int n, m, Q, K, T;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int a[maxn];
int dsum[maxn];

signed main() {
  // file(a);
  n = read();
  rep(i, 1, n) a[i] = read();
  dsum[n] = a[n];
  drep(i, n - 1, 1) dsum[i] = (dsum[i + 1] + a[i]) % mod;
  int ans = 0;
  rep(i, 1, n - 1) { ans = (ans + 1ll * a[i] * dsum[i + 1] % mod) % mod; }
  printf("%lld\\n", ans);

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

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

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

  string ss;
  int ans = 0, cnt = 0;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    ss = s.substr(i, t.size());
    for (int j = 0; j < t.size(); j++) {
      if (ss.at(j) == t.at(j))
        cnt++;
    }
    if (cnt > ans)
      ans = cnt;
    cnt = 0;
  }
  cout << t.size() - ans << endl;
  return 0;
}


Error: 0

Fixed submission:

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

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

  int j = 0, cnt = 0;
  vector<int> ans;
  rep(i, s.size()) {
    if (t.at(j) == s.at(i)) {
      cnt++;
      j++;
    } else if (cnt > 0) {
      ans.push_back(cnt);
      cnt = 0;
      j = 0;
      if (t.at(j) == s.at(i)) {
        cnt++;
        j++;
      }
    }
  }
  sort(ans.begin(), ans.end(), greater<int>());

  if (ans.size() > 0)
    cout << t.size() - ans.at(0) << endl;
  else
    cout << t.size() << endl;
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  int M = T.size();
  int ans = T.size();

  for (int i = 0; i <= N - M; i++) {
    int count = 0;
    for (int j = 0; j < M; j++) {
      if (T.at(j) != S.at(j + i))
        count++;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  int M = T.size();
  int count = M;
  int ans = M;

  for (int i = 0; i < N - M + 1; i++) {
    int j = 0;
    while (S.at(i) == T.at(j)) {
      count--;
      i++;
      j++;
    }
    ans = min(ans, count);
  }
  if (ans == M)
    ans--;
  cout << ans << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, s, t, l1, l2, l, m, r, f;
  char str1[1005];
  char str2[1006];
  scanf("%s", str1);
  scanf("%s", str2);
  l1 = strlen(str1);
  l2 = strlen(str2);
  t = 0;
  for (i = 0; i <= (l1 - l2); i++) {
    s = 0;
    r = 0;
    for (j = 0, l = i; j < l2; l++, j++) {
      if (str1[l] == str2[j]) {
        s++;
      }
    }
    if (s > t) {
      t = s;
      m = i;
    }
    // printf("%d\\n",t);
  }
  f = l2 - t;
  // printf("%d\\n",m);
  // r = 0;
  // for(i = m,j = 0;j < l2;i++,j++){
  //   if(str1[i] != str2[j]){
  //     r++;
  // }
  //}
  printf("%d\\n", f);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, s, t, l1, l2, l, m, r, f;
  char str1[1005];
  char str2[1006];
  scanf("%s", str1);
  scanf("%s", str2);
  l1 = strlen(str1);
  l2 = strlen(str2);
  t = 0;
  for (i = 0; i <= (l1 - l2); i++) {
    s = 0;
    // r = 0;
    for (j = 0, l = i; j < l2; l++, j++) {
      if (str1[l] == str2[j]) {
        s++;
      }
    }
    if (s > t) {
      t = s;
      m = i;
      // f = r;
    }
    // printf("%d\\n",t);
  }
  // printf("%d\\n",m);
  r = 0;
  for (i = m, j = 0; j < l2; i++, j++) {
    if (str1[i] != str2[j]) {
      r++;
    }
  }
  printf("%d\\n", r);
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int i, d = 0, c = 0, j;
  for (i = 0; i <= a.size() - b.size(); i++) {
    c = 0;
    for (j = i; j <= i + b.size() - 1; j++) {
      if (a[j] == b[j - i]) {
        c++;
      }
    }
    if (c > d) {
      d = c;
    }
  }
  cout << b.size() - d;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int i, d = 0, c = 0, j;
  for (i = 0; i <= a.size() - b.size() - 1; i++) {
    c = 0;
    for (j = i; j <= i + b.size() - 1; j++) {
      if (a[j] == b[j - i]) {
        c++;
      }
    }
    if (c > d) {
      d = c;
    }
  }
  cout << b.size() - d;
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int max = 0;
  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    int c = 0;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] == t[j]) {
        c++;
      }
    }
    if (max < c)
      max = c;
  }
  cout << t.length() - max << '\\n';
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int l = t.length();
  int max = 0;
  for (int ts = t.length(); ts > 0; ts--) {
    for (int k = 0; k < t.length() - ts + 1; k++) {
      for (int j = k; j < (s.length() - ts + 1 - (ts - k - 1)); j++) {
        bool result = true;
        for (int i = 0; i < ts; i++) {
          if (s[j + i] != t[k + i]) {
            result = false;
            break;
          }
        }
        if (result) {
          cout << t.length() - ts << '\\n';
          return 0;
        }
      }
    }
  }
  cout << t.length() << '\\n';
  return 0;
}