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

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

#define fast_IO                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
#define pb push_back
#define F first
#define S second
#define int long long int
#define ll long long
#define ld long double

bool isPrime(ll n) {
  if (n < 2)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

ll lcm(ll x, ll y) { return (x * y) / (__gcd(x, y)); }

signed main() {
  fast_IO;
  int t = 1;
  // cin>>t;
  while (t--) {
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    for (int i = 0; i + t.length() - 1 < s.length(); i++) {
      int p = 0, cnt = 0;
      for (int j = i; j < i + t.length(); j++) {
        if (s[j] != t[p++])
          cnt++;
      }
      ans = min(ans, cnt);
    }
    cout << ans;
  }
  return 0;
}

Error: WA

Fixed submission:

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

#define fast_IO                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
#define pb push_back
#define F first
#define S second
#define int long long int
#define ll long long
#define ld long double

bool isPrime(ll n) {
  if (n < 2)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

ll lcm(ll x, ll y) { return (x * y) / (__gcd(x, y)); }

signed main() {
  fast_IO;
  int t = 1;
  // cin>>t;
  while (t--) {
    string s, t;
    cin >> s >> t;
    int ans = s.size();
    for (int i = 0; i < s.length() - t.length() - 1; i++) {
      int p = 0, cnt = 0;
      for (int j = i; j < i + t.length(); j++) {
        if (s[j] != t[p++])
          cnt++;
      }
      ans = min(ans, cnt);
    }
    cout << ans;
  }
  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 max_same = 0;
  int countsame;
  for (int i = 0; i < S.size(); i++) {
    if (i + T.size() <= S.size()) {
      countsame = 0;
      for (int j = 0; j < T.size(); j++) {
        if (S.at(i + j) == T.at(j)) {
          countsame++;
        }
      }
      if (countsame > max_same) {
        max_same = countsame;
      }
    }
  }
  int ans = T.size() - max_same;
  cout << ans << endl;

  return 0;
}


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


Fixed submission:

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

int main() {
  string S, T;
  cin >> S >> T;
  int min_same = 10000;
  int countsame = 0;
  for (size_t i = 0; i < S.size(); i++) {
    countsame = 0;
    for (size_t j = 0; j < T.size(); j++) {
      if (S.at(i + j) == T.at(j)) {
        countsame++;
      }
    }
    if (countsame < min_same) {
      min_same = countsame;
    }
  }
  int ans = T.size() - countsame;
  cout << ans << endl;

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

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

int main() {
  string s, t;
  int a = 0, k = 0;

  cin >> s >> t;

  rep(i, (int)s.size() - (int)t.size() + 1) {

    rep(j, (int)t.size()) {
      if (s.at(i + j) == t.at(j))
        a++;
    }
    k = max(k, a);
    a = 0;
    /*for(int i=j;i<(int)s.size()-j;i++){



      /*if(s.at(i)==t.at(j)){
        while(s.at(i+a)==t.at(j+a) && i+a<(int)s.size() && j+a<(int)t.size()){
          a++;
        }
        k=max(k,a);
        a=0;
      }
        */
    //}
    // cout << k << endl;
  }

  cout << (int)t.size() - k << endl;
  ;
}

Error: 0

Fixed submission:

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

int main() {
  string s, t;
  int a = 0, k = 0;

  cin >> s >> t;

  rep(j, (int)t.size()) {
    for (int i = j; i < (int)s.size() - j; i++) {

      if (s.at(i) == t.at(j)) {
        while (s.at(i + a) == t.at(j + a) && i + a < (int)s.size() &&
               j + a < (int)t.size()) {
          a++;
        }
        k = max(k, a);
        a = 0;
      }
    }
    // cout << k << endl;
  }

  cout << (int)t.size() - k << 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 i = 0; i < S.size() - T.size() + 1; i++) {
    int count = 0;
    for (int j = 0; j < T.size(); j++) {
      if (T.at(j) != S.at(i + j))
        count++;
    }
    ans = min(ans, count);
  }
  cout << ans << 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 = T.size();

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

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
  char s[1010], t[1010];
  int ndif[1010] = {};

  cin >> s;
  cin >> t;

  int len = strlen(s) - strlen(t);

  for (int i = 0; i <= len; i++) {
    for (int j = 0; j < strlen(t); j++) {
      if (t[j] != s[j + i])
        ndif[i]++;
    }
  }

  cout << *min_element(ndif, ndif + len) << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
  char s[1010], t[1010];
  int ndif[1010] = {}, ans = 0, num = 0, len = strlen(s) - strlen(t);
  int min = 1000;
  cin >> s;
  cin >> t;

  for (unsigned int i = 0; i < len; i++) {
    for (int j = 0; j < strlen(t); j++) {
      if (t[j] != s[j + i])
        ndif[i]++;
    }
  }

  for (unsigned int i = 0; i < len; i++) {
    if (ndif[i] - min < 0) {
      num = i;
      min = ndif[i];
    }
  }

  for (int i = 0; i < strlen(t); i++) {
    if (t[i] != s[i + num])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

// const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

  int count = 0;
  for (size_t i = 0; i < s.size() - t.size() + 1; i++) {
    string str = s.substr(i, t.size());
    int matchCount = 0;
    for (size_t j = 0; j < str.size(); j++) {
      if (str[j] == t[j]) {
        matchCount++;
      }
    }
    count = max(count, matchCount);
  }

  cout << (t.size() - count) << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoll


Fixed submission:

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

  ll count = 0;
  for (ll i = 0; i < stoll(s) - stoll(t); i++) {
    string str = s.substr(i, stoll(t));
    ll matchCount = 0;
    for (ll j = 0; j < stoll(str); j++) {
      if (str[j] == t[j]) {
        matchCount++;
      }
    }
    count = max(count, matchCount);
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {

  long long int n, i, j = 1, c = 0, f = 10000000000, l, k, x, y, z, m, b,
                      a = 10000000;
  string s, w = "", s1;
  cin >> s >> w;
  n = w.length();

  for (i = 0; i < s.length() - n + 1; i++) {
    c = 0;
    s1 = s.substr(i, n);
    for (j = 0; j < w.length(); j++) {
      if (s1[j] != w[j])
        c++;
      // cout<<s[j]<<" "<<w[j]<<endl;
    }
    a = min(a, c);
    // break;
  }
  cout << a << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {

  int n, i, j = 1, c = 0, l, k, x, y, z, m, b, a = 100000;
  string s, w, s1;
  cin >> s >> w;
  n = w.length();
  for (i = 0; i < s.length(); i++) {
    c = 0;
    s1 = s.substr(i, w.length());
    for (j = 0; j < w.length(); j++) {
      if (s1[j] == w[j])
        c++;
      // cout<<s[j]<<" "<<w[j]<<endl;
    }
    a = min(a, n - c);
    // break;
  }
  cout << a << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ;
   Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// #define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define all(vec) vec.begin(), vec.end()
#define endl "\\n"
ll google_itr = 1;
#define google(x) cout << "Case #" << x << ":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void virus() {
  string s, t;
  cin >> s >> t;
  vector<ll> ans;
  for (auto i = 0; i <= (ll)s.size() - (ll)t.size(); i++) {
    ll mis = 0;
    for (auto j = 0; j < (ll)t.size(); j++) {
      if (s[i + j] != t[j])
        mis++;
    }
    ans.push_back(mis);
  }

  cout << *min_element(ans.begin(), ans.end());
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

  ll t = 1;
  // cin>>t;
  while (t--) {
    auto start = high_resolution_clock::now();
    virus();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    cerr << "\\n Time: " << duration.count() << endl;
    // your code goes here
  }
  return 0;
}

Error: WA

Fixed submission:

/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ;
   Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// #define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define all(vec) vec.begin(), vec.end()
#define endl "\\n"
ll google_itr = 1;
#define google(x) cout << "Case #" << x << ":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void virus() {
  string s, t;
  cin >> s >> t;
  vector<ll> ans;
  for (auto i = 0; i < (ll)s.size() - (ll)t.size() - 1; i++) {
    ll mis = 0;
    for (auto j = 0; j < (ll)t.size(); j++) {
      if (s[i + j] != t[j])
        mis++;
    }
    ans.push_back(mis);
  }
  cout << *min_element(ans.begin(), ans.end());
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

  ll t = 1;
  // cin>>t;
  while (t--) {
    auto start = high_resolution_clock::now();
    virus();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    cerr << "\\n Time: " << duration.count() << endl;
    // your code goes here
  }
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 100000 + 5;
// ------------------------------------
vector<int> v;
// ------------------------------------
// 1 is tru

int main() {
  string s, t, subs;
  int a = 0;
  cin >> s >> t;
  v.push_back(t.length());

  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i] == t[j]) {
        if (i - j >= 0 && i - j + t.length() <= s.length()) {
          subs = s.substr(i - j, t.length());
          for (int k = 0; k < t.length(); k++) {
            if (subs[k] != t[k]) {
              a++;
            }
          }
          v.push_back(a);
          a = 0;
        }
      }
    }
  }
  cout << *min_element(v.begin(), v.end()) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 100000 + 5;
// ------------------------------------
vector<int> v;
// ------------------------------------
// 1 is tru

int main() {
  string s, t, subs;
  int a = 0;
  cin >> s >> t;

  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i] == t[j]) {
        if (i - j >= 0 && i - j + t.length() <= s.length()) {
          subs = s.substr(i - j, t.length());
          for (int k = 0; k < t.length(); k++) {
            if (subs[k] != t[k]) {
              a++;
            }
          }
          v.push_back(a);
          a = 0;
        }
      }
    }
  }
  cout << *min_element(v.begin(), v.end()) << endl;
}
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;
using ll = long long;
using P = pair<int, int>;
int main() {
  string S, T;
  cin >> S >> T;
  ll b = S.size() - T.size();
  ll ans = T.size();
  rep(i, b + 1) {
    ll counter = 0;
    rep(j, T.size()) {
      if (S.at(i + j) != T.at(j)) {
        counter++;
      }
    }
    ans = min(ans, counter);
  }
  cout << ans << endl;
}

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 S, T;
  cin >> S >> T;
  ll a = 0, b = S.size() - T.size();
  vector<int> X(b);
  rep(i, b) {
    ll counter = 0;
    rep(j, T.size()) {
      if (S.at(i + j) != T.at(j)) {
        counter++;
      }
    }
    X.at(i) = counter;
  }
  sort(X.begin(), X.end());
  cout << X.at(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 s, t, n;
  s = S.size();
  t = T.size();
  n = s - t + 1;
  // 一番合ってるやつを探す
  // 前から後へ
  vector<int> c(n);
  int cmax = 0;
  for (int i = 0; i < n; i++) {
    // 何個一致してるかをｃで表す
    for (int j = 0; j < t; j++) {
      if (S.at(i + j) == T.at(j)) {
        c.at(i)++;
      }
    }
    // 最大値を更新していく
    if (c.at(i) > cmax) {
      cmax = c.at(i);
    }
  }
  cout << t - cmax << 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 s, t, n;
  s = S.size();
  t = T.size();
  n = s - t + 1;
  // 一番合ってるやつを探す
  // 前から後へ
  vector<int> c(t);
  int cmax = 0;
  for (int i = 0; i < n; i++) {
    // 何個一致してるかをｃで表す
    for (int j = 0; j < t; j++) {
      if (S.at(i + j) == T.at(j)) {
        c.at(i)++;
      }
    }
  }
  // 最大値を更新していく
  for (int i = 0; i < t; i++) {
    if (c.at(i) > cmax) {
      cmax = c.at(i);
    }
  }
  cout << t - cmax << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main() {

  string t, s;
  cin >> s >> t;

  int sts = s.size() - t.size();
  int ts = t.size();
  std::vector<int> v(sts, 0);

  if (sts == 0) {
    if (t == s) {
      cout << 0 << endl;
    } else {
      int sum = 0;
      for (int i = 0; i < ts; i++) {
        if (t.at(i) != s.at(i)) {
          sum++;
        }
      }
      cout << sum << endl;
    }
    return 0;
  }

  for (int i = 0; i < sts; i++) {
    for (int j = 0; j < ts; j++) {
      if (t.at(j) != s.at(i + j)) {
        v.at(i)++;
      }
    }
  }
  sort(all(v));

  cout << v.at(0) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main() {

  string t, s;
  cin >> s >> t;

  int a = s.size() - t.size();
  int ts = t.size();
  std::vector<int> v(a, 0);

  for (int i = 0; i < a; i++) {
    for (int j = 0; j < ts; j++) {
      if (t.at(j) != s.at(i + j)) {
        v.at(i)++;
      }
    }
  }
  sort(all(v));

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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 10000;
  for (int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
    int cnt = 0;
    string l = s.substr(i, (int)t.size());
    for (int j = 0; j < (int)t.size(); j++) {
      if (l.at(j) != t.at(j))
        cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  string s, t;
  cin >> s >> t;
  int sum = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    int cnt = 0;
    bool exist = false;
    for (int k = 0; k < (int)t.size(); k++) {
      if (s.at(i) == t.at(k))
        exist = true;
    }
    if (exist) {
      cnt++;
      if (i != (int)s.size() - 1) {
        for (int j = i + 1; cnt < (int)t.size(); j++) {
          if (s.at(j) == t.at(cnt))
            cnt++;
          else
            break;
        }
      }
    }
    sum = max(sum, cnt);
  }
  cout << (int)t.size() - sum << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #define int long long
using namespace std;
const int MOD = 1e9 + 7;
int32_t main() {
  string s, t;
  cin >> s >> t;
  int ans = t.length();
  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    // if(s[i]==t[i]){
    int st = 0;
    int d = 0;
    for (; st < t.length(); st++) {
      if (t[st] != s[i + st]) {
        d++;
      }
    }
    ans = min(ans, d);
    //}
  }
  cout << ans << "\\n";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
// #define int long long
using namespace std;
const int MOD = 1e9 + 7;
int32_t main() {
  string s, t;
  cin >> s >> t;
  int ans = t.length();
  for (int i = 0; i < s.length() - t.length() - 1; i++) {
    // if(s[i]==t[i]){
    int st = i;
    int d = 0;
    for (; st < i + t.length(); st++) {
      if (t[st] != s[st]) {
        d++;
      }
    }
    ans = min(ans, d);
    //}
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
#define ios                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define endl '\\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}

int main() {
  ios;
  string s, t;
  cin >> s >> t;
  int k = t.size();
  int mn = k;
  for (int i = 0; i < s.size() - k + 1; i++) {
    int cnt = 0;
    string m = "";
    for (int j = i; s[j]; j++) {

      m += s[j];
      cnt++;
      if (cnt == k)
        break;
    }
    int c = 0;
    for (int l = 0; t[l]; l++) {
      if (m[l] != t[l])
        c++;
    }
    mn = min(mn, c);
  }
  cout << mn << endl;
}


Error: 0

Fixed submission:

// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
#define ios                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define endl '\\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}

int main() {
  ios;
  string s, t;
  cin >> s >> t;
  int k = t.size();
  int mn = k;
  for (int i = 0; s[i]; i++) {
    int cnt = 0;
    string m = "";
    for (int j = i; s[j]; j++) {

      m[cnt] = s[j];
      cnt++;
      if (cnt == k)
        break;
    }
    int c = 0;
    for (int l = 0; t[l]; l++) {
      if (m[l] != t[l])
        c++;
    }
    mn = min(mn, c);
  }
  cout << mn << endl;
}
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  string S, T;
  int i, j;
  int diff, ans;

  cin >> S >> T;
  ans = T.size();

  for (i = 0; i <= S.size() - T.size(); i++) {

    diff = 0;
    for (j = 0; j < T.size(); j++) {

      if (T[j] != S[i + j]) {
        diff++;
      }
    }

    ans = min(ans, diff);
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {

  string S, T;
  int i = 1;
  int imax = 0, dmax = 0;

  cin >> S >> T;

  while (S.find(T.substr(0, (int)(T.length()) - i)) == std::string::npos) {

    i = i + 1;

    if (T.length() == i) {
      break;
    }
  }

  if (i == (int)(T.length())) {
    imax = i;
  } else {
    imax = i;
  }

  i = 1;
  while (S.find(T.substr((int)(T.length()) - i, i)) != std::string::npos) {

    if (S.find(T.substr((int)(T.length()) - i, i)) >= (int)T.length() - i) {
      i++;
    } else {
      break;
    }

    if (i == T.length()) {
      break;
    }
  }

  if (i == (int)(T.length())) {
    dmax = i;
  } else {
    dmax = (int)(T.length()) - i + 1;
  }

  cout << min(imax, dmax) << endl;
}