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

#include <cctype>
#include <cstdio>

int main() {
  int sum;
  char line[1002];

  while (true) {
    sum = 0;
    scanf("%s", line);
    for (int i = 0; isdigit(line[i]); i++) {
      sum += line[i] - '0';
    }

    if (sum == 0) {
      break;
    }

    printf("%d\\n", sum);
  }

  return 0;
}


Error: 0

Fixed submission:

#include <cctype>
#include <cstdio>

int main() {
  int sum;
  char line[6];

  while (true) {
    sum = 0;
    scanf("%s", line);
    for (int i = 0; isdigit(line[i]); i++) {
      sum += line[i] - '0';
    }

    if (sum == 0) {
      break;
    }

    printf("%d\\n", sum);
  }

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


#include <iostream>

using namespace std;

int main() {
  string num;
  long sum;

  while (true) {
    cin >> num;
    if (num == "0") {
      break;
    }
    sum = 0;
    for (int i = 0; i < num.length(); i++) {
      sum += num[i] - '0';
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  long n;
  string n_str;
  int sum;

  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    sum = 0;

    n_str = to_string(n);
    for (int i = 0; i < n_str.length(); i++) {
      sum += n_str[i] - '0';
    }
    cout << sum << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string x;
  int a;
  while (1) {
    cin >> x;
    if (x == "0")
      break;
    a = 0;
    for (int i = 0; i < x.length(); i++)
      a += x[i] - '0';
    cout << a << endl;
  }
}

Error: TLE

Fixed submission:

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

  while (1) {
    long int x;
    long int sum = 0;
    cin >> x;
    if (x == 0)
      break;
    for (long int i = x; i >= 1; i /= 10) {
      sum += i % 10;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error


#include <cstdio>

int main() {
  char num[1000];
  int sum, i, n;
  for (;;) {
    scanf("%s", num);
    i = 0;
    sum = 0;
    while (num[i] != 0) {
      sum = sum + (num[i] - '0');
      i++;
    }
    if (sum == 0) {
      break;
    }
    printf("%d\\n", sum);
  }
  return 0;
}


Error: 0

Fixed submission:


#include <cstdio>

int main() {
  char num[900];
  int sum, i, n;
  for (;;) {
    scanf("%s", num);
    i = 0;
    sum = 0;
    while (num[i] != 0) {
      sum = sum + (num[i] - '0');
      i++;
    }
    if (sum == 0) {
      break;
    }
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  string A;
  while (1) {
    cin >> A;
    if (A == "0") {
      break;
    } else {
      int sum = 0;
      for (int i = 0; i < A.size(); i++) {
        int number;
        number = A[i] - '0';
        sum += number;
      }
      cout << sum << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  string num;
  while (num != "0") {
    scanf("%s", &num);
    int sum = 0;
    for (int i = 0; i < num.size(); i++) {
      int number;
      number = num[i] - '0';
      sum += number;
    }
    printf("%d.¥n", sum);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>
#define rep(i, a) for (int i = 0; i < a; ++i)

int main(void) {
  char s[1500];
  int i, ans = 0;
  while (1) {
    ans = 0;
    scanf("%s", s);
    if (strlen(s) == 1 && s[0] == '0')
      break;
    rep(i, strlen(s)) ans += s[i] - '0';
    printf("%d\\n", ans);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
#define rep(i, a) for (int i = 0; i < a; ++i)

int main(void) {
  char s[1500];
  int i, ans = 0;
  while (1) {
    ans = 0;
    scanf("%s", s);
    if (strlen(s) == 1 && s[0] == 0)
      break;
    rep(i, strlen(s)) ans += s[i] - '0';
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  string n;
  while (1) {
    cin >> n;
    if (n == "0")
      break;
    int a = 0, b = 0, i;
    for (i = 0; i < n.length(); ++i) {
      a = n[i] - '0';
      b = b + a;
    }
    cout << b << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

  while (1) {
    int x, y = 0;
    cin >> x;
    if (x = 0)
      break;

    while (1) {
      if (x = 0)
        break;
      y += x % 10;
      x = x / 10;
    }
    cout << y << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>

int main() {
  char str[1001];

  while (1) {
    scanf("%s", str);
    if (str[0] == '0')
      break;
    int sum = 0;
    for (int i = 0; i < strlen(str); i++) {
      sum += (str[i] - '0');
    }

    printf("%d\\n", sum);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

int main() {
  char str[1001];
  while (1) {
    scanf("%s", str);
    if (str[0] == 0)
      break;
    int sum = 0;
    for (int i = 0; i < strlen(str); i++) {
      sum += (str[i] - '0');
    }

    printf("%d\\n", sum);
  }

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  vector<string> X;
  for (;;) {
    string s;
    cin >> s;
    if (s == "0")
      break;
    X.push_back(s);
  }

  for (int i = 0; i < X.size(); i++) {
    int sum = 0;
    string x = X.at(i);
    for (int j = 0; j < x.size(); j++) {
      sum += (int)(x.at(j) - '0');
    }
    cout << sum << endl;
  }
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  vector<int> X;
  for (;;) {
    int x;
    cin >> x;
    if (x == 0)
      break;
    X.push_back(x);
  }

  for (int i = 0; i < X.size(); i++) {
    int sum = 0;
    int x = X.at(i);
    for (;;) {
      sum += x % 10;
      x /= 10;
      if (x == 0)
        break;
    }
    cout << sum << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int i;
  char number[1001] = {0};
  int sum = 0;

  while (1) {
    sum = 0;
    cin >> number;

    for (i = 0; number[i] != '\\0'; i++) {
      sum += number[i] - '0';
    }
    if (number[0] == '0')
      break;
    cout << sum << "\\n";
  }
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int i;
  char number[5] = {0};
  int sum = 0;

  while (1) {
    sum = 0;
    cin >> number;

    for (i = 0; number[i] != '\\0'; i++) {
      sum += number[i] - '0';
    }
    if (number[0] == '0')
      break;
    cout << sum << "\\n";
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {

  while (true) {
    string num;
    cin >> num;
    if (num == "0")
      break;
    int size = num.size();

    int a[1000];
    for (int i = 0; i < size; ++i) {
      a[i] = num[i] - '0';
    }
    int sum = 0;
    for (int j = 0; j < size; ++j) {
      sum += a[j];
    }
    cout << sum << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int x;
  int a, b, c, d;
  int temp1, temp2;
  int sum = 0;

  while (true) {
    sum = 0;
    cin >> x;
    if (x == 0)
      break;

    a = x / 1000;
    // cout << a << endl;
    temp1 = x % 1000;
    b = temp1 / 100;
    // cout << b << endl;
    temp2 = temp1 % 100;
    c = temp2 / 10;
    // cout << c << endl;
    d = temp2 % 10;
    // cout << d << endl;

    sum += a;
    sum += b;
    sum += c;
    sum += d;

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


#include <iostream>
using namespace std;

int main() {
  char in[1000];
  while (true) {
    int s = 0;
    int i = 0;
    cin >> in;
    if (in[i] == '0') {
      break;
    }
    while (in[i]) {
      s = s + in[i] - '0';
      i++;
    }
    cout << s << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  char in[50];
  while (true) {
    int s = 0;
    int i = 0;
    cin >> in;
    if (in[i] == '0') {
      break;
    }
    while (in[i]) {
      s = s + in[i] - '0';
      i++;
    }
    cout << s << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string s;
  while (cin >> s, s != "0") {
    int sum = 0;
    for (int i = 0; i < s.size(); ++i) {
      sum += s[i] - '0';
    }
    cout << sum << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (1) {
    int a, b = 1, x, num = 0, total = 0, result = 0;
    cin >> x;
    if (x == 0)
      break;
    a = (int)log10((double)x);
    for (int i = 0; i <= a; i++) {
      for (int j = 0; j < a - i; j++)
        b *= 10;
      num = (int)(x - total) / b;
      // cout << num << ":" << total << ":" << b <<  endl;
      total += num * b;
      b = 1;
      result += num;
    }
    cout << result << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {

  while (1) {

    string num;

    cin >> num;

    if (num[0] == '0')
      break;

    int sum = 0;

    for (int i = 0; i < num.size(); i++) {

      sum += num[i] - '0';
    }

    cout << sum << endl;
  }
}


Error: TLE

Fixed submission:

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

  while (1) {

    char num[1001];

    cin >> num;

    if (num == 0)
      break;

    int sum;

    for (int i = 0; i < 1001; i++) {

      sum += num[i] - '0';
    }

    cout << sum << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

// ITP1_8_B
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int sum, i;
  char c;

  for (sum = 0;; sum = 0) {
    for (i = 0;; i++) {
      c = getchar();
      if (c == '\\n') {
        cout << sum << endl;
        break;
      } else if (c == '0' && i == 0)
        return 0;
      sum += c - '0';
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

// ITP1_8_B
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int sum, i;
  char c;

  for (sum = 0;; sum = 0) {
    for (i = 0;; i++) {
      c = getchar();
      if (c == '\\n') {
        cout << sum << endl;
        break;
      } else if (c == '0' && i == 0)
        break;
      sum += c - '0';
    }
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
int main() {
  while (true) {
    string x;
    cin >> x;
    if (x == "0")
      break;
    int sum = 0;
    for (int i = 0; i < x.size(); i++) {
      sum += x[i] - '0';
    }
    cout << sum << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
int main() {
  while (true) {
    string x;
    if (x == "0")
      break;
    int sum = 0;
    for (int i = 0; i < x.size(); i++) {
      sum += x[i] - '0';
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {

  int soma = 0;

  char n[] = {"123456789"};

  while (true) {
    char x[1000] = {0};
    scanf("%s", &x);

    if (x[0] == '0')
      return 0;

    soma = 0;

    for (int i = 0; i < 1000; i++) {
      switch (x[i]) {
      case '1':
        soma += 1;
        break;
      case '2':
        soma += 2;
        break;
      case '3':
        soma += 3;
        break;
      case '4':
        soma += 4;
        break;
      case '5':
        soma += 5;
        break;
      case '6':
        soma += 6;
        break;
      case '7':
        soma += 7;
        break;
      case '8':
        soma += 8;
        break;
      case '9':
        soma += 9;
        break;
      }
    }
    printf("%d\\n", soma);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {

  char x[1000] = {0};
  char n[] = {"123456789"};

  while (true) {
    int soma = 0;
    scanf("%s", &x);

    for (int i = 0; i < 1000; i++) {
      switch (x[i]) {
      case '1':
        soma += 1;
        break;
      case '2':
        soma += 2;
        break;
      case '3':
        soma += 3;
        break;
      case '4':
        soma += 4;
        break;
      case '5':
        soma += 5;
        break;
      case '6':
        soma += 6;
        break;
      case '7':
        soma += 7;
        break;
      case '8':
        soma += 8;
        break;
      case '9':
        soma += 9;
        break;
      }
    }
    printf("%d\\n", soma);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string a;
  int ans;
  while (1) {
    ans = 0;
    cin >> a;
    if (a == "0")
      break;
    for (int i = 0; i < a.size(); i++) {
      ans += a[i] - '0';
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int a, ans, t, c, A;
  while (1) {
    ans = 0;
    t = 10;
    cin >> a;
    if (a == 0)
      break;
    A = a;
    while (a / t > 0) {
      t *= 10;
    }
    for (int i = t / 10; i >= 10; i /= 10) {
      ans += a / i;
      a %= i;
    }
    ans += a % 10;
    cout << ans << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string x;
  char tmp;
  int sum;

  cin >> x;

  while (x != "0") {
    sum = 0;

    for (int i = 0; i < x.size(); i++) {
      tmp = x[i];

      sum += atoi(&tmp);
    }

    cout << sum << endl;
    cin >> x;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  long long x, tmp;
  long long sum;

  cin >> x;

  while (x != 0) {
    tmp = x;
    sum = 0;

    while (tmp != 0) {
      sum += tmp % 10;
      tmp /= 10;
    }

    cout << sum << endl;

    cin >> x;
  }

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

#include <iostream>
using namespace std;

int main() {
  string number;
  int sum[1000];
  int j = 0;
  while (1) {
    sum[j] = 0;
    cin >> number;
    if (number == "0") {
      sum[j] = 0;
      break;
    }
    for (int i = 0; i < number.length(); i++) {
      sum[j] += number[i] - '0';
    }
    j++;
  }
  j = 0;
  while (1) {
    if (sum[j] == 0)
      break;
    cout << sum[j] << endl;
    j++;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  string number;
  int sum[100];
  int j = 0;
  while (1) {
    sum[j] = 0;
    cin >> number;
    if (number == "0") {
      sum[j] = 0;
      break;
    }
    for (int i = 0; i < number.length(); i++) {
      sum[j] += number[i] - '0';
    }
    j++;
  }
  j = 0;
  while (1) {
    if (sum[j] == 0)
      break;
    cout << sum[j] << endl;
    j++;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {

  char inp;
  int ans, flag;

  while (1) {
    ans = 0;
    flag = 0;
    while (1) {
      inp = getchar();
      if (inp == '0' && flag == 0)
        goto a;
      flag = 1;
      if (inp == '\\n')
        break;
      ans += inp - '0';
    }
    cout << ans << endl;
  }
a:
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {

  char inp;
  int ans;

  while (1) {
    ans = 0;
    while (1) {
      inp = getchar();
      if (inp == '\\n')
        break;
      ans += inp - '0';
    }
    cout << ans << endl;
  }

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

#include <stdio.h>
char number[1001];
int main() {
  int x, sum;
  sum = 1;
  while (sum != 0) {
    sum = 0;
    while ((x = getchar()) != '\\n') {
      sum += x - '0';
    }
    if (sum == 0) {
      break;
    }
    printf("%d\\n", sum);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
char number[1001];
int main() {
  int x, sum;
  sum = 1;
  while (sum != 0) {
    sum = 0;
    while ((x = getchar()) != '\\n') {
      sum += x - 'o';
    }
    if (sum == 0) {
      break;
    }
    printf("%D\\n", sum);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string num;
  int n = 0;

  while (1) {
    cin >> num;
    if (num[0] == '0')
      break;
    for (int i = 0; i < num.size(); i++) {
      n += num[i] - '0';
    }
    cout << n << endl;
    n = 0;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  string num;
  int n = 0;

  while (1) {
    cin >> num;
    if (num[0] == 0)
      break;
    for (int i = 0; i < num.size(); i++) {
      n += num[i] - '0';
    }
    cout << n << endl;
  }
  return 0;
}
Problem p02418 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char s[100], p[100], z[300] = "";
  scanf("%s", s);
  scanf("%s", p);
  strcat(z, s);
  strcat(z, s);

  printf("%s\\n", strstr(z, p) ? "Yes" : "No");
}

Error: 0

Fixed submission:

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

int main() {
  char s[200], p[100];
  scanf("%s", s);
  scanf("%s", p);
  strcat(s, s);

  printf("%s\\n", strstr(s, p) ? "Yes" : "No");
}
Problem p02418 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[201], s2[101], p[101];
  cin >> s;
  cin >> p;
  strcpy(s2, s);
  strcat(s, s2);
  if (strstr(s, p)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[101], p[101];
  cin >> s;
  cin >> p;
  strcat(s, s);
  if (strstr(s, p)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02418 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char s1[1000], s2[1000], s3[1000];

  scanf("%s %s", s1, s2);

  strcpy(s3, s1);

  if (strstr(strcat(s1, s3), s2) == NULL)
    printf("No\\n");
  else
    printf("Yes\\n");

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  char s1[1000], s2[1000];

  scanf("%s %s", s1, s2);

  if (strstr(strcat(s1, s1), s2) == NULL)
    printf("No\\n");
  else
    printf("Yes\\n");

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

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

#include <cstdio>
#include <cstring>

int main() {
  char s[202], t[202], p[101];

  scanf("%s %s", s, p);
  strcpy(t, s);
  strcat(s, t);
  if (strstr(s, p) == NULL)
    cout << "No\\n";
  else
    cout << "Yes\\n";

  return 0;
}

Error: 0

Fixed submission:

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

#include <cstdio>
#include <cstring>

int main() {
  char s[202], p[101];

  scanf("%s %s", s, p);
  strcat(s, s);
  if (strstr(s, p) == NULL)
    cout << "No\\n";
  else
    cout << "Yes\\n";

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

#include <stdio.h>
#include <string.h>
int main(void) {
  char a[101], b[101], c[201];
  scanf("%s%s", a, b);
  strcat(c, a);
  strcat(c, a);
  if (strstr(c, b) == NULL)
    puts("No");
  else
    puts("Yes");

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>
int main(void) {
  char a[201], b[101];
  scanf("%s%s", a, b);
  char x[201];
  strcat(a, a);
  if (strstr(a, b) == NULL)
    puts("No");
  else
    puts("Yes");

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

#include <stdio.h>
// s: a raw text, p: a pattern text
// p in s ? true:false
char s[101];
char p[101];
int main() {
  int i, n, j, flag, pflag;
  scanf("%s", s);
  scanf("%s", p);
  for (i = 0; s[i] != '\\0'; ++i) {
    pflag = 0;
    for (n = i, flag = 0; s[n == 0 ? 0 : n - 1] != '\\0' && pflag == 0;) {
      for (j = 0; p[j] != '\\0' && pflag == 0; ++j) {
        // printf("%d!!%d:%d, %c:%c\\n",i, n, j, s[n], p[j]);
        if (s[n] == '\\0') {
          // printf("loop%d:%d, %c:%c\\n", n, j, s[n], p[j]);
          if (flag != 0) {
            pflag = 1;
          }
          flag++;
          n = 0;
          j--;
          continue;
        }
        if (s[n++] != p[j])
          break;
        if (p[j + 1] == '\\0') {
          printf("Yes\\n");
          return 0;
        }
      }
      if (j != 0) {
        --n;
      } else {
      }
    }
  }
  printf("No\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
// s: a raw text, p: a pattern text
// p in s ? true:false
char s[101];
char p[101];
int main() {
  int i, n, j, flag, pflag;
  scanf("%s", s);
  scanf("%s", p);
  for (i = 0; s[i] != '\\0'; ++i) {
    pflag = 0;
    for (n = i, flag = 0; s[n == 0 ? 0 : n - 1] != '\\0';) {
      for (j = 0; p[j] != '\\0' && pflag == 0; ++j) {
        // printf("%d!!%d:%d, %c:%c\\n",i, n, j, s[n], p[j]);
        if (s[n] == '\\0') {
          // printf("loop%d:%d, %c:%c\\n", n, j, s[n], p[j]);
          if (flag != 0) {
            pflag = 1;
          }
          flag++;
          n = 0;
          j--;
          continue;
        }
        if (s[n++] != p[j])
          break;
        if (p[j + 1] == '\\0') {
          printf("Yes\\n");
          return 0;
        }
      }
      if (j != 0) {
        --n;
      } else {
      }
    }
  }
  printf("No\\n");
  return 0;
}
Problem p02418 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  char s[100], p[100], s2[200];
  cin >> s >> p;
  strcpy(s2, s);
  strcat(s2, s);

  if (strstr(s2, p) != NULL) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  char s[200], p[100];
  cin >> s >> p;
  strcat(s, s);

  if (strstr(s, p) != NULL) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}