alexjercan/bugnet huggingface dataset:
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
char a;
int kotae[26], b;
int main(void) {
  while (1) {
    if (scanf(" %c", &a) == EOF)
      break;
    for (int j = 0; j < 26; j++) {
      if (a == 'a' + j || a == 'A' + j) {
        kotae[j] += 1;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << (char)('a' + i) << " : " << kotae[i] << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
char a;
int kotae[26], b;
int main(void) {
  while (1) {
    scanf(" %c", &a);
    if (a == '.')
      break;
    for (int j = 0; j < 26; j++) {
      if (a == 'a' + j || a == 'A' + j) {
        kotae[j] += 1;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << (char)('a' + i) << " : " << kotae[i] << endl;
  }
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

  int c[26] = {0};

  char ch;

  while (cin >> ch) {

    if (isalpha(ch)) {

      if (isupper(ch)) {

        char ch1 = tolower(ch);

        int num = ch1 - 'a';

        c[num] += 1;

      } else {

        int num = ch - 'a';

        c[num] += 1;
      }
    }
  }

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

    char alpha = i + 'a';

    cout << alpha << ' ' << ':' << ' ' << c[i] << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

  int c[26] = {0};

  char ch;

  while (1) {

    scanf("%s", &ch);

    if (ch == '\\n')
      break;

    if (isalpha(ch)) {

      if (isupper(ch)) {

        ch = tolower(ch);

        int num = ch - 'a';

        c[num] += 1;

      } else {

        int num = ch - 'a';

        c[num] += 1;
      }
    }
  }

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

    char alpha = i + 'a';

    cout << alpha << ' ' << ':' << ' ' << c[i] << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int counter[26];

  char ch;

  for (int x = 0; x <= 25; x++) {
    counter[x] = 0;
  }

  while (cin >> ch) {
    if (isupper(ch)) {
      ch = tolower(ch);
    }
    int num = ch - 'a';

    if (num >= 0 && num <= 25) {
      counter[num]++;
    }
  }

  for (int x = 0; x <= 25; x++) {
    char y = x + 'a';
    cout << y << ' ' << ':' << ' ';
    cout << counter[x] << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int counter[25];

  char ch;

  for (int x = 0; x <= 25; x++) {
    counter[x] = 0;
  }

  while (cin >> ch) {
    int num = ch - 'a';

    if (num >= 0 && num <= 25) {
      counter[num]++;
    }
  }

  for (int x = 0; x <= 25; x++) {
    char y = x + 'a';
    cout << y << ':';
    cout << counter[x] << endl;
  }

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

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

int main(void) {
  int count[26] = {0};
  char c;

  while (cin >> c) {

    if (c >= 65 && c <= 90)
      count[c - 'A']++;
    else if (c >= 97 && c <= 122)
      count[c - 'a']++;
  }

  for (int i = 0; i < 26; i++)
    printf("%c : %d\\n", ('a' + i), count[i]);
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int count[26] = {0};

  while (1) {
    char c;
    if (c >= 65 && c <= 90)
      count[c - 'A']++;
    else if (c >= 97 && c <= 122)
      count[c - 'a']++;

    if (c == '.')
      break;
  }

  for (int i = 0; i < 26; i++)
    printf("%c : %d\\n", ('a' + i), count[i]);
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  int z[26];
  for (int k = 0; k < 26; k++) {
    z[k] = 0;
  }
  while (1) {
    getline(cin, s);
    if (s == "")
      break;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] >= 'a' && s[i] <= 'z')
        z[(int)s[i] - 'a']++;
      else if (s[i] >= 'A' && s[i] <= 'Z')
        z[(int)s[i] - 'A']++;
    }
  }
  for (int j = 0; j < 26; j++) {
    cout << (char)(j + 97) << " : " << z[j] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  int z[26];
  for (int k = 0; k < 26; k++) {
    z[k] = 0;
  }
  while (1) {
    getline(cin, s);
    for (int i = 0; i < s.size(); i++) {
      if (s[i] >= 'a' && s[i] <= 'z')
        z[(int)s[i] - 'a']++;
      else if (s[i] >= 'A' && s[i] <= 'Z')
        z[(int)s[i] - 'A']++;
    }
    for (int j = 0; j < 26; j++) {
      cout << (char)(j + 97) << " : " << z[j] << endl;
    }
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <ctype.h>
#include <stdio.h>
int main() {
  int c;
  int cnt[500] = {0};
  while (c != EOF) {
    c = getchar();
    if (islower(c)) {
      cnt[c]++;
    } else {
      cnt[c + 32]++;
    }
  }
  for (c = 'a'; c <= 'z'; c++) {
    printf("%c : %d\\n", c, cnt[c]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <ctype.h>
#include <stdio.h>
int main() {
  int c;
  int cnt[500] = {0};
  while (c != '.') {
    c = getchar();
    if (islower(c)) {
      cnt[c]++;
    } else {
      cnt[c + 32]++;
    }
  }
  for (c = 'a'; c <= 'z'; c++) {
    printf("%c : %d\\n", c, cnt[c]);
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int countTable[256] = {0};
  char ch;

  while ((ch = getchar()) != EOF) {
    countTable[ch]++;
  }
  for (int i = 97; i <= 122; i++)
    printf("%c : %d\\n", i, countTable[i] + countTable[i - 32]);
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int countTable[256] = {0};
  char current, history = 's';

  while ((current = getchar()) != '\\n' || history != '\\n') {
    countTable[current]++;
    history = current;
  }
  for (int i = 97; i <= 122; i++)
    printf("%c : %d\\n", i, countTable[i] + countTable[i - 32]);
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string r;
  int c;
  char ny;
  while (scanf("%c", &ny) != EOF) {

    // if(ny==EOF)break;
    r += ny;
  }
  char a = 'a';
  int count[26] = {0}; // aが0,zが25

  for (int i = 0; i < r.size(); i++) {
    for (int j = 0; j < 26; j++) {
      r[i] = tolower(r[i]);
      if (r[i] - 'a' == j)
        count[j]++;
    }
  }
  for (int i = 0; i < 26; i++) {
    printf("%c : %d\\n", a, count[i]);
    a++;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }

  for (int i = 0; i < a.size() - 1; i++) {
    for (int j = i + 1; j < a.size(); j++) {
      if (a[i] > a[j])
        swap(a[i], a[j]);
    }
  }
  for (int i = 0; i < a.size() - 1; i++)
    cout << a[i] << " ";
  cout << a[a.size() - 1] << endl;

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

#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char ch;
  int num;
  int counter[26] = {};

  while (scanf("%c", &ch) != EOF) {

    if (isalpha(ch)) {
      if (islower(ch)) {
        int num = ch - 'a';
        counter[num] += 1;
      }

      else if (isupper(ch)) {
        int num = ch - 'A';
        counter[num] += 1;
      }
    }
  }

  for (int i = 0; i < 26; i++) {
    ch = i + 'a';

    cout << ch << " "
         << ":"
         << " " << counter[i] << endl;
  }
}


Error: TLE

Fixed submission:

#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char ch;
  int num;
  int counter[26] = {};

  while (1) {
    scanf("%c", &ch);

    if (isalpha(ch)) {
      if (islower(ch)) {
        int num = ch - 'a';
        counter[num] += 1;
      }

      else if (isupper(ch)) {
        int num = ch - 'A';
        counter[num] += 1;
      }
    }

    if (ch == '.')
      break;
  }

  for (int i = 0; i < 26; i++) {
    ch = i + 'a';

    cout << ch << " "
         << ":"
         << " " << counter[i] << endl;
  }
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int cnt[26] = {};
  char ch;

  while (cin >> ch) {
    ch = tolower(ch);
    if (isalpha(ch))
      cnt[ch - 'a']++;
  }

  for (int i = 0; i <= 25; i++) {
    cout << (char)(i + 'a') << " : " << cnt[i] << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int cnt[25] = {};
  char ch;

  while (cin >> ch) {
    ch = tolower(ch);
    if (isalpha(ch))
      cnt[ch - 'a']++;
  }

  for (int i = 0; i <= 25; i++) {
    cout << (char)(i + 'a') << " : " << cnt[i] << endl;
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

#include <ctype.h>
#include <stdio.h>
char c[1200];
int cnt[27];
int main() {
  char ch;
  int n;
  while (scanf("%s", c) != EOF) {
    for (int i = 0; c[i] != '\\0'; ++i) {
      ch = tolower(c[i]);
      n = ch - '0';
      if (n < 49 || n > 74)
        continue;
      ++cnt[n - 49];
    }
  }
  for (int i = 0; i < 26; ++i)
    printf("%c : %d\\n", i + 97, cnt[i]);
  return 0;
}


Error: 0

Fixed submission:

#include <ctype.h>
#include <stdio.h>
char c[1200];
int cnt[26];
int main() {
  char ch;
  int n;
  while (scanf("%s", c) != EOF) {
    for (int i = 0; c[i] != '\\0'; ++i) {
      ch = tolower(c[i]);
      n = ch - '0' - 49;
      ++cnt[n];
    }
  }
  for (int i = 0; i < 26; ++i)
    printf("%c : %d\\n", i + 97, cnt[i]);
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int i, k = 0, j;
  char a, cou[27];
  for (i = 0; i < 28; i++) {
    cou[i] = 0;
  } // syokika
  //  for(i=0;i<1201;i++){
  while (scanf("%c", &a) != EOF) {
    // printf("%c\\n", a);
    if ('a' <= a && a <= 'z') {
      cou[a - 'a' + 1] += 1;
    }
    if ('A' <= a && a <= 'Z') {
      cou[a - 'A' + 1] += 1;
    }
  }
  // printf("hoge\\n");
  for (j = 'a'; j <= 'z'; j++) {
    k += 1;
    printf("%c : %d\\n", j, cou[k]);
  }
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <stdio.h>
int main() {
  int i, k = 0, j;
  char a, cou[1][26];
  for (i = 0; i < 1200; i++) {
    scanf("%c", &a);
    if ('a' <= a && a <= 'z') {
      cou[1][a - 'a' + 1] += 1;
    }
  }
  for (j = 'a'; j <= 'z'; j++) {
    k += 1;
    printf("%c : %d\\n", j, cou[1][k]);
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ALPHABET_NUM ('z' - 'a' + 1)
using namespace std;

int main(int argc, char *argv[]) {
  vector<int> num(ALPHABET_NUM, 0);

  char c;
  while (cin >> c) {
    if (!('A' <= c && c <= 'Z') && !('a' <= c && c <= 'z'))
      continue;
    if ('A' <= c && c <= 'Z')
      c += 'a' - 'A';
    num[c - 'a']++;
  }

  for (int i = 0; i < num.size(); i++) {
    cout << (char)('a' + i) << " : " << num[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

#define ALPHABET_NUM ('z' - 'a' + 1)
using namespace std;

int main(int argc, char *argv[]) {
  vector<int> num(ALPHABET_NUM, 0);

  while (true) {
    string str;
    getline(cin, str);
    for (string::iterator itr = str.begin(); itr != str.end(); itr++) {
      char c = *itr;
      if (!('A' <= c && c <= 'Z') && !('a' <= c && c <= 'z'))
        continue;
      if ('A' <= c && c <= 'Z')
        c += 'a' - 'A';
      num[c - 'a']++;
    }
  }

  for (int i = 0; i < num.size(); i++) {
    cout << (char)('a' + i) << " : " << num[i] << endl;
  }

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

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

// ?°????????????§????????????
void toUpper(char *str) {
  int len = strlen(str);
  if (len <= 0) {
    return;
  }
  for (int i = 0; i < len; i++) {
    if (str[i] >= 'a' && str[i] <= 'z') {
      str[i] &= 0xdf; //?°????????????§??????
    }
  }
}

int main(void) {

  char word[16];
  char sentense[1024];
  char t[1024];
  char tmp[16];

  int num[50];
  int combo[50];

  scanf("%s", word);
  toUpper(word);
  int cnt = 0;
  while (fgets(sentense, 1024, stdin) != NULL) {
    if (strcmp(sentense, "END_OF_TEXT\\n") == 0) {
      break;
    }
    toUpper(sentense);
    int len = strlen(sentense);
    if (len > 0) {
      sentense[len - 1] = '\\0';
    }
    char *ptr = strtok(sentense, " ");
    while (ptr != NULL) {
      if (strcmp(ptr, word) == 0) {
        cnt++;
      }
      ptr = strtok(NULL, " ");
    }
  }

  printf("%d\\n", cnt);

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {

  char search_word[12];
  char sentense[1001];
  char div_word[1001];
  char c;
  char *pst, *pend, *pnow;
  int cnt = 0;
  int ii;

  scanf("%s", search_word);
  scanf("%c", &c);
  for (ii = 0; ii < (int)strlen(search_word); ii++) {
    search_word[ii] &= 0xdf;
  }

  for (;;) {
    fgets(sentense, 1000, stdin);
    sentense[strlen(sentense) - 1] = '\\0';
    if (!strcmp(sentense, "END_OF_TEXT")) {
      break;
    }
    pst = pnow = sentense;
    do {
      pend = strstr(pst, " ");
      if (pend == NULL) {
        pend = &sentense[strlen(sentense)];
      }
      for (; pnow < pend; pnow++) {
        div_word[pnow - pst] = (*pnow) & 0xdf;
      }
      div_word[pnow - pst] = '\\0';
      if (!strcmp(div_word, search_word)) {
        cnt++;
      }
      pst = pnow = pend + 1;
    } while (pst < &sentense[strlen(sentense)]);
  }
  printf("%d\\n", cnt);
  // getchar();
  return 0;
}
Problem p02419 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;
int main() {
  string t, w;
  int c = 0, i;
  size_t pos;
  cin >> w;
  while ((cin >> t) && (t != "END_OF_TEXT")) {
    for (int i = 0; i < t.length(); i++) {
      if (t[i] >= 'A' && t[i] <= 'Z')
        t[i] += 'a' - 'A';
    }
    pos = 0;
    if (t == w)
      c++;
  }
  printf("%d\\n", c);
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;
int main() {
  string t, w;
  int c = 0, i;
  cin >> w;
  while (getline(cin, t) && (t != "END_OF_TEXT")) {
    i = 0;
    while (i <= t.length()) {
      int tm = t.find(w, i);
      if (tm != -1) {
        cout << tm << endl;
        c++;
        i += tm + w.length() - 1;
      }
    }
  }
  printf("%d", c);
  return 0;
}
Problem p02419 (C++) — buggy submission, verdict: Time Limit Exceeded

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

char tolower(char c);
int main() {
  int count = 0;
  string W, str;
  cin >> W;
  while (1) {
    cin >> str;
    if (str == "END_OF_TEXT")
      break;
    for (int i = 0; i < (int)str.size(); i++) {
      str[i] = tolower(str[i]);
    }
    if (str == W)
      count++;
  }
  cout << count << endl;
  return 0;
}

char tolower(char c) {
  if ('A' <= c && c <= 'Z') {
    return c - 'A' + 'a';
  } else
    return c;
}


Error: TLE

Fixed submission:

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

char tolower(char c);
int main() {
  int count;
  string W;
  cin >> W;
  while (1) {
    string str;
    if (str == "END")
      break;
    for (int i = 0; i < (int)str.size(); i++) {
      str[i] = tolower(str[i]);
    }
    if (str == W)
      count++;
  }
  cout << count << endl;
  return 0;
}

char tolower(char c) {
  if ('A' <= c && c <= 'Z') {
    return c - 'A' + 'Z';
  } else
    return c;
}
Problem p02419 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  std::string word;
  std::cin >> word;
  std::transform(word.begin(), word.end(), word.begin(), ::tolower);

  int cnt = 0;
  std::string text;
  while (1) {
    std::cin >> text;
    if (text == "END_OF_TEXT")
      break;
    std::transform(text.begin(), text.end(), text.begin(), ::tolower);
    if (text == word)
      cnt++;
  }
  std::cout << cnt << std::endl;

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>

int main() {
  std::string word;
  std::string text;
  std::getline(std::cin, word);

  int cnt = 0;
  while (1) {
    std::getline(std::cin, text);
    if (text == "END_OF_TEXT")
      break;
    for (int i = 0; text[i] != '0'; ++i) {
      if (isupper(text[i]))
        text[i] = tolower(text[i]);
    }

    if (text == word)
      cnt++;
  }
  std::cout << cnt << std::endl;

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

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

int main() {
  int a = 0; // a??????????????????????????????
  string str1, str2;
  cin >> str2;

  while (1) {
    cin >> str1;
    if (str1 == "END_OF_TEXT")
      break;
    for (int i = 0; i < str1.size(); i++)
      str1[i] = tolower(str1[i]);
    if (str1 == str2)
      a++;
  }

  cout << a << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a;
  string str1, str2;
  cin >> str2;

  while (1) {
    cin >> str1;

    for (int i = 0; i < str1.size(); i++)
      str1[i] = tolower(str1[i]);

    if (str1 == "END_OF_TEXT")
      break;
    if (str1 == str2)
      a++;
  }

  cout << a << endl;

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

// class point	の練習（クラスの高度な実装）
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

typedef long long llong;
using namespace std;

void lower(char *x) {
  for (int i = 0; x[i] != '\\0'; i++) {
    if (65 <= x[i] && x[i] <= 90)
      x[i] += 32;
  }
  return;
}

int main() {
  char W[20];
  char T[1100];
  int cnt = 0;
  scanf("%s", W);
  while (1) {
    scanf("%s", T);
    if (!strcmp(T, "END_OF_TEXT"))
      break;
    lower(T);
    if (!strcmp(W, T))
      cnt++;
  }
  cout << cnt << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

// class point	の練習（クラスの高度な実装）
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

typedef long long llong;
using namespace std;

void lower(char *x) {
  for (int i = 0; x[i] != '\\0'; i++) {
    if (65 <= x[i] && x[i] <= 90)
      x[i] += 32;
  }
  return;
}

int main() {
  char W[20];
  char T[1100];
  char IPT[20];
  int Wlength;
  int cnt = 0;
  fgets(IPT, 20, stdin);
  strcpy(W, IPT);
  W[strlen(IPT) - 1] = '\\0';
  Wlength = strlen(W);
  while (1) {
    fgets(T, 1050, stdin);
    if (!strcmp(T, "END_OF_TEXT\\n"))
      break;
    lower(T);
    for (int i = 0; T[i] != '\\n'; i++) {
      if (T[i] == W[0]) {
        for (int j = 0; j < Wlength; j++) {
          if (T[i + j] != W[j])
            break;
          else if (j == Wlength - 1)
            cnt++;
        }
      }
    }
  }
  cout << cnt << '\\n';
  return 0;
}
Problem p02419 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  int result(0);
  string arg;
  cin >> arg;

  for (int i2(0), n2(arg.length()); i2 < n2; ++i2) {
    if ('A' <= arg[i2] && arg[i2] <= 'Z') {
      arg[i2] = arg[i2] - 'A' + 'a';
    }
  }

  while (1) {
    string tmp;
    cin >> tmp;

    if (tmp == "END_OF_TEXT") {
      cout << result << endl;
      return 0;
    }

    for (int i2(0), n2(tmp.length()); i2 < n2; ++i2) {
      if ('A' <= tmp[i2] && tmp[i2] <= 'Z') {
        tmp[i2] = tmp[i2] - 'A' + 'a';
      }
    }

    if (tmp == arg) {
      ++result;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int result(0);
  string arg;
  cin >> arg;

  while (1) {
    string tmp;
    cin >> tmp;

    for (int i2(0), n2(tmp.length()); i2 < n2; ++i2) {
      if ('A' <= tmp[i2] && arg[i2] <= 'Z') {
        tmp[i2] = tmp[i2] - 'A' + 'a';
      }
    }

    if (tmp == "end_of_text") {
      cout << result; // << endl;
      return 0;
    }

    if (tmp == arg) {
      ++result;
    }
  }
}
Problem p02419 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string W;
  string T;
  string END = "END_OF_TEXT";
  int count = 0;
  cin >> W;

  while (1) {
    cin >> T;

    if (T == END) {
      break;
    }

    // transform(T.begin(), T.end(), T.begin(), tolower);
    transform(T.begin(), T.end(), T.begin(), ::tolower);
    if (T == W) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int NUM = 1000;
  string W;
  string T[NUM];
  int count = 0;
  int length = 0;
  cin >> W;
  while (1) {
    for (int i = 0; i < NUM; i++) {
      cin >> T[i];
      if (T[i] == "END_OF_TEXT") {
        length = i;
        break;
      }
    }
  }

  for (int i = 0; i < NUM; i++) {
    if (T[i] == W)
      count++;
  }
  cout << count << endl;
  return 0;
}
Problem p02419 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string p;
  string in;
  string s[10000] = {""};
  getline(cin, p);
  int n = 0;
  int k = 0;
  int q = 0;
  bool j = true;
  while (1) {
    getline(cin, in);
    for (int i = 0; i < in.length(); i++) {
      if (in[i] == 32) {
        k++;
      } else {
        s[k] += in[i];
      }
    }
    for (; q <= k; q++) {
      if (s[q] == "END_OF_TEXT") {
        j = false;
      }
      string l = s[q];
      transform(l.begin(), l.end(), l.begin(), ::tolower);
      if (l == p) {
        n++;
      }
    }
    k++;
    if (j == false)
      break;
  }
  cout << n << endl;
}


Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_M_create


Fixed submission:

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

int main() {
  string p;
  string in;
  string s[10000] = {""};
  getline(cin, p);
  int n = 0;
  int k = 0;
  int q = 0;
  bool j = true;
  while (1) {
    getline(cin, in);
    for (int i = 0; i < in.length(); i++) {
      if (in[i] == 32) {
        k++;
      } else {
        s[k] += tolower(in[i]);
      }
    }
    for (; q <= k; q++) {
      string l = s[q];
      //  transform(s[q].begin(), s[q].end(), l.begin(), ::tolower
      //);
      if (s[q] == "END_OF_TEXT") {
        j = false;
      } else if (s[q] == p) {
        n++;
      }
    }
    k++;
    if (j == false)
      break;
  }
  cout << n << endl;
}