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

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

int main() {
  char c;
  int nI[27] = {0};
  while (cin >> c) {
    int n = tolower(c);
    nI[n - '`'] += 1;
  }
  for (int i = 1; i < 27; i++) {
    printf("%c : %d\\n", '`' + i, nI[i]);
  }
  // system("pause");
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  char c;
  int nI[27] = {0};
  while (cin >> c, c != '.') {
    int nA = 0, na = 0;
    nA = c - '@';
    na = c - '`';
    if (na > 0 && nA > 0) {
      nI[na] += 1;
    } else {
      nI[nA] += 1;
    }
  }
  for (int i = 1; i < 27; i++) {
    printf("%c : %d\\n", '`' + i, nI[i]);
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int main() {
  string a, e;
  int i, d[26];
  for (i = 0; i < 26; i++) {
    d[i] = 0;
  }
  char b;
  while (1) {
    getline(cin, e);
    a += e;
    if (e == "") {
      break;
    }
  }
  string::iterator s;
  for (s = a.begin(); s != a.end(); s++) {
    *s = tolower(*s);
  }
  for (i = 0; i < 26; i++) {
    for (s = a.begin(); s != a.end(); s++) {
      b = 97 + i;
      if (*s == b) {
        d[i] += 1;
      }
    }
  }
  for (i = 0; i < 26; i++) {
    b = 97 + i;
    cout << b << " : " << d[i] << endl;
  }
  return 0;
}

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


Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string a, e;
  int i, d[26];
  for (i = 0; i < 26; i++) {
    d[i] = 0;
  }
  char b;
  while (1) {
    getline(cin, e);
    a += e;
    if (e.substr(1, 1) == "") {
      break;
    }
  }
  string::iterator s;
  for (s = a.begin(); s != a.end(); s++) {
    *s = tolower(*s);
  }
  for (i = 0; i < 26; i++) {
    for (s = a.begin(); s != a.end(); s++) {
      b = 97 + i;
      if (*s == b) {
        d[i] += 1;
      }
    }
  }
  for (i = 0; i < 26; i++) {
    b = 97 + i;
    cout << b << " : " << d[i] << endl;
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {

  map<char, int> ans;
  string str;

  while (cin >> str) {
    for (int i = 0; i < str.size(); ++i) {
      ++ans[str[i]];
    }
  }

  char a;
  map<char, int>::iterator itr1, itr2;
  for (int i = 0; i < 26; ++i) {
    itr1 = ans.find('a' + i);
    itr2 = ans.find('A' + i);
    a = 'a' + i;
    cout << a << " : " << itr1->second + itr2->second << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {

  map<char, int> ans;
  string str;

  while (true) {
    cin >> str;
    for (int i = 0; i < str.size(); ++i) {
      ++ans[str[i]];
    }
    if (str.find(".") != string::npos && str.find("Mr.") == string::npos) {
      break;
    }
  }

  char a;
  map<char, int>::iterator itr1, itr2;
  for (int i = 0; i < 26; ++i) {
    itr1 = ans.find('a' + i);
    itr2 = ans.find('A' + i);
    a = 'a' + i;
    cout << a << " : " << itr1->second + itr2->second << endl;
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  vector<string> s;
  string temps;
  while (cin >> temps) {
    s.push_back(temps);
  }
  int cnt[26] = {};
  for (vector<string>::iterator i = s.begin(); i != s.end(); i++) {
    for (int j = 0; j < i->length(); j++) {
      if ((*i)[j] >= 'a' && (*i)[j] <= 'z') {
        (*i)[j] += 'A' - 'a';
      }
      if ((*i)[j] >= 'A' && (*i)[j] <= 'Z') {
        cnt[(int)((*i)[j] - 'A')]++;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    printf("%c : %d\\n", i + 'a', cnt[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  vector<string> s;
  string temps;
  do {
    getline(cin, temps);
    s.push_back(temps);
  } while (temps[temps.length() - 1] != '.');
  int cnt[26] = {};
  for (vector<string>::iterator i = s.begin(); i != s.end(); i++) {
    for (int j = 0; j < i->length(); j++) {
      if ((*i)[j] >= 'a' && (*i)[j] <= 'z') {
        (*i)[j] += 'A' - 'a';
      }
      if ((*i)[j] >= 'A' && (*i)[j] <= 'Z') {
        cnt[(int)((*i)[j] - 'A')]++;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    printf("%c : %d\\n", i + 'a', cnt[i]);
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int count[26];

int main() {
  char c;
  while (1) {
    cin >> c;
    if (cin.eof())
      break;
    if (c < 'a')
      c += 32;
    if (c < 'a' || c > 'z')
      continue;
    count[c - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    c = 'a' + i;
    cout << c << " : " << count[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int count[26];

int main() {
  char c;
  while (1) {
    scanf("%c", &c);
    if (c == '.')
      break;
    if (c < 'a')
      c += 32;
    if (c == ' ')
      continue;
    count[c - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    c = 'a' + i;
    cout << c << " : " << count[i] << endl;
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  char chara[1200]; // 文字列
  int count[26];    // 文字のカウント配列
  // 初期化
  for (int i = 0; i < 1200; i++)
    chara[i] = 0;
  for (int i = 0; i < 26; i++)
    count[i] = 0;
  // コンソール読み込み
  while (fgets(chara, sizeof(chara), stdin) != NULL) {
    for (int i = 0; i < sizeof(chara); i++) {
      int ch = chara[i];
      if (ch < 65 || ch > 122)
        continue;
      if (ch >= 97 && ch <= 122)
        ch = ch - 32; // 小文字を大文字に
      count[ch - 65] += 1;
    }
    for (int i = 0; i < 1200; i++)
      chara[i] = 0; // 初期化
  }
  for (int i = 0; i < sizeof(count) / 4; i++) {
    printf("%c : %d\\n", 97 + i, count[i]);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
int main(void) {
  // Here your code !
  char chara[1200];
  int count[26];
  int i = 0;
  // 初期化
  for (int i = 0; i < 26; i++)
    count[i] = 0;
  // コンソール読み込み
  fgets(chara, sizeof(chara), stdin);
  fputs(chara, stdout);
  for (i = 0; i < sizeof(chara); i++) {
    int ch = chara[i];
    if (ch < 65 || ch > 122)
      continue;
    if (ch >= 97 && ch <= 122)
      ch = ch - 32; // 小文字を大文字に
    count[ch - 65] += 1;
  }
  for (int i = 0; i < sizeof(count) / 4; i++) {
    printf("%c : %d\\n", 65 + i, count[i]);
  }
  getchar();
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <iostream>

#define MAX_LEN (1200)

using namespace std;

int main() {
  char *str = new char[MAX_LEN + 1];
  int *counter = new int[26];

  for (int i = 0; i < 26; i++) {
    counter[i] = 0;
  }

  while (cin >> str) {
    for (int i = 0; str[i] != '\\0'; i++) {
      if (str[i] >= 'A' && str[i] <= 'Z') {
        str[i] = tolower(str[i]);
      }

      if (str[i] >= 'a' && str[i] <= 'z') {
        int num = str[i] - 'a';
        counter[num]++;
      }
    }
  }

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

  delete[] str;
  delete[] counter;

  return (0);
}

Error: TLE

Fixed submission:

#include <cctype>
#include <iostream>

using namespace std;

int main() {
  char ch;

  while (1) {
    cin >> ch;

    if (ch != '\\n') {
      if (ch >= 'A' && ch <= 'Z') {
        cout << tolower(ch);
      } else if (ch >= 'a' && ch <= 'z') {
        cout << toupper(ch);
      } else {
        cout << ch;
      }
    } else {
      cout << endl;
      break;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  unordered_multiset<string> parts;
  vector<string> alphabet;
  for (int i = 97; i < 123; i++) {
    alphabet.push_back(string(1, (char)i));
  }

  char tmpc;
  while (cin >> tmpc) {
    parts.insert(string(1, tolower(tmpc)));
  }
  for (auto var : alphabet) {
    cout << var << " : " << parts.count(var) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  unordered_multiset<string> parts;
  vector<string> alphabet;
  for (int i = 97; i < 123; i++) {
    alphabet.push_back(string(1, (char)i));
  }
  while (1) {
    string word;
    cin >> word;
    for (auto var : word) {
      parts.insert(string(1, tolower(var)));
    }
    if (*(word.end() - 1) == '.')
      break;
  }
  for (auto var : alphabet) {
    cout << var << " : " << parts.count(var) << endl;
  }

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

#include <cstdio>
#include <string.h>

int main() {

  int eachalphabetnum[26];

  for (int i = 0; i < 26; i++) {
    eachalphabetnum[i] = 0;
  }

  char s[1200];

  while (scanf("%s", s) != EOF) {

    for (int i = 0; s[i] != '\\0'; i++) {

      char c = s[i];

      if (c >= 65 && c <= 90) {
        eachalphabetnum[c - 65]++;
      } else if (c >= 97 && c <= 122) {
        eachalphabetnum[c - 97]++;
      }
    }
  }

  for (int i = 0; i < 26; i++) {
    char d = i + 97;
    std::printf("%c : %d\\n", d, eachalphabetnum[i]);
  }
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <string.h>

int main() {

  int eachalphabetnum[26];

  char s[1200];

  while (scanf("%[^\\n]", s) != EOF) {

    for (int i = 0; i < 26; i++) {
      eachalphabetnum[i] = 0;
    }

    for (int i = 0; s[i] != '\\0'; i++) {

      char c = s[i];

      if (c >= 65 && c <= 90) {
        eachalphabetnum[c - 65]++;
      } else if (c >= 97 && c <= 122) {
        eachalphabetnum[c - 97]++;
      }
    }
  }

  for (int i = 0; i < 26; i++) {
    char d = i + 97;
    std::printf("%c : %d\\n", d, eachalphabetnum[i]);
  }
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int counter[26];

int main() {
  bool end = false;
  while (!end) {
    string str;
    getline(cin, str);
    if (str.size() == 0)
      break;
    for (int i = 0; i < str.size(); i++) {
      char charactor = str.at(i);
      if ('A' <= charactor && charactor <= 'Z')
        charactor += 32;
      if ('a' <= charactor && charactor <= 'z')
        counter[charactor - 'a']++;
    }
    str = "";
  }
  for (int i = 0; i < 26; i++)
    cout << (char)(i + 'a') << " : " << counter[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int counter[26];

int main() {
  bool end = false;
  while (!end) {
    string str;
    getline(cin, str);
    for (int i = 0; i < str.size(); i++) {
      char charactor = str.at(i);
      if ('A' <= charactor && charactor <= 'Z')
        charactor += 32;
      if ('a' <= charactor && charactor <= 'z')
        counter[charactor - 'a']++;
    }
    if (str.at(str.size() - 1) == '.')
      end = true;
    str = "";
  }
  for (int i = 0; i < 26; i++)
    cout << (char)(i + 'a') << " : " << counter[i] << endl;
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string str;
  int num[26] = {0};

  char ch;
  while (cin >> ch) {

    if (islower(ch)) {
      num[ch - 'a']++;
    } else if (isupper(ch)) {
      num[ch - 'A']++;
    }
  }

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

  return (0);
}

Error: TLE

Fixed submission:

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

int main() {
  string str;
  int num[26] = {0};
  bool EoS = false;

  while (1) {
    getline(cin, str);

    for (int i = 0; i < str.size(); i++) {
      if (islower(str[i])) {
        num[str[i] - 'a']++;
      } else if (isupper(str[i])) {
        num[str[i] - 'A']++;
      } else if (str[i] == '.') {
        EoS = true;
      }
    }

    if (EoS) {
      for (int i = 0; i < 26; i++) {
        char c = 'a' + i;
        cout << c << " : " << num[i] << endl;
      }
      break;
    }
  }

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

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

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

  for (; cin >> ch;) {

    int num = tolower(ch) - 'a';
    if (0 <= num && num <= 25) {
      counter[num] += 1;
    }
  }

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

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int counter[26];
  char ch;

  while (cin >> ch) {
    int num = ch - 'a';
    if (0 <= num && num <= 26) {
      counter[num]++;
    }
  }

  for (int i = 0; i <= 26; i++) {
    char al = i + 'a';
    cout << al << ":" << counter[i] << endl;
  }

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

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

std::vector<int> count(std::string s, std::vector<int> v);
void print(std::vector<int> v);

int main(void) {
  std::string s;
  std::vector<int> v(26, 0);

  while (std::getline(std::cin, s)) {
    int len = (int)(s.length());
    v = count(s, v);
  }
  print(v);
  return EXIT_SUCCESS;
}

std::vector<int> count(std::string s, std::vector<int> v) {
  int len = (int)(s.length());
  int diff = int('a') - int('A');
  for (int i = 0; i < len; i++) {
    if ((int)(s[i]) >= int('A') && (int)(s[i]) <= int('Z')) {
      s[i] += diff;
    }
    if ((int)(s[i]) >= int('a') && (int)(s[i]) <= int('z')) {
      v[(int)(s[i]) - (int)('a')]++;
    }
  }
  return v;
}

void print(std::vector<int> v) {
  int size = (int)(v.size());
  for (int i = 0; i < size; i++) {
    char word = (char)((int)('a') + i);
    std::cout << word << " : " << v[i] << std::endl;
  }
}

Error: 0

Fixed submission:

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

std::string changeString(std::string s);
std::vector<int> count(std::string s, std::vector<int> v);
void print(std::vector<int> v);

int main(void) {
  std::string s;
  std::vector<int> v(26, 0);

  while (std::getline(std::cin, s)) {
    int len = (int)(s.length());
    s = changeString(s);
    v = count(s, v);
  }
  print(v);
  return EXIT_SUCCESS;
}

std::string changeString(std::string s) {
  int len = (int)(s.length());
  for (int i = 0; i < len; i++) {
    int diff = int('a') - int('A');
    if ((int)(s[i]) >= int('A') && (int)(s[i]) <= int('Z')) {
      s[i] += diff;
    }
  }
  return s;
}

std::vector<int> count(std::string s, std::vector<int> v) {
  int len = (int)(s.length());
  for (int i = 0; i < len; i++) {
    v[(int)(s[i]) - (int)('a')]++;
  }
  return v;
}

void print(std::vector<int> v) {
  int size = (int)(v.size());
  for (int i = 0; i < size; i++) {
    char word = (char)((int)('a') + i);
    std::cout << word << " : " << v[i] << std::endl;
  }
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>

#define A_NUM 26
using namespace std;

int main(void) {

  char ch;
  int alpha[A_NUM] = {};

  while (scanf("%c", &ch) != EOF) {
    if (isalpha(ch)) {
      if (isupper(ch))
        ch = tolower(ch);
      alpha[(int)(ch - 'a')]++;
    }
  }

  for (int i = 0; i < A_NUM; i++) {
    printf("%c : %d\\n", (char)(i + 'a'), alpha[i]);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <iostream>

#define A_NUM 26
using namespace std;

int main(void) {

  char c;
  int alpha[A_NUM];

  while (1) {
    cin >> c;
    if (c == '\\n')
      break;
    if (isalpha(c)) {
      if (isupper(c))
        c = tolower(c);
      alpha[c - 'a']++;
    }
  }

  for (int i = 0; i < A_NUM; i++) {
    cout << (char)('a' + i) << " : " << alpha[i] << "\\n";
  }
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

#include <cctype>
#include <cstdio>

int main() {
  int i = 0, a[26] = {0};
  char ch;

  while (scanf("%c", &ch) != EOF) {
    if (isupper(ch))
      ch = tolower(ch);

    if ('a' <= ch && ch <= 'z')
      ++a[ch - 'a'];

    ++i;
  }

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

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>
int main() {
  char ch;
  int num[26] = {}, b, k;
  while (scanf("%c", &ch) != EOF) {
    if ('A' <= ch && ch <= 'Z') {
      k = ch + '32';
      b = k - 'a';
      num[b] += 1;
    } else if ('a' <= ch && ch <= 'z') {
      b = ch - 'a';
      num[b] += 1;
    }
  }
  for (int i = 0; i < 26; i++) {
    printf("%c : %d\\n", i + 'a', num[i]);
  }
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char c[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  vector<int> ans(26, 0);
  string str;
  char ch;
  while (cin >> ch) {
    // getline(cin,str);
    // for(int i=0; i<(int)str.size(); i++){
    // cout<<(str[i]-'0')<<endl;//-49
    // int n=str[i]-'0';
    int n = ch - '0';
    if (49 <= n && n <= 74) {
      ans[n - 49] += 1;
    } else if (17 <= n && n <= 42) {
      ans[n - 17] += 1;
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << c[i] << " : " << ans[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  char c[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  vector<int> ans(26, 0);
  string str;
  while (1) {
    getline(cin, str);
    for (int i = 0; i < (int)str.size(); i++) {
      // cout<<(str[i]-'0')<<endl;//-49
      int n = str[i] - '0';
      if (49 <= n && n <= 74) {
        ans[n - 49] += 1;
      } else if (17 <= n && n <= 42) {
        ans[n - 17] += 1;
      }
    }
    for (int i = 0; i < ans.size(); i++) {
      cout << c[i] << " : " << ans[i] << endl;
    }
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

static const int ALPHABETS = 26;

int main(void) {
  int alp[ALPHABETS] = {0};
  int c;

  while ((c = getchar()) != EOF) {
    if ('a' <= c && c <= 'z')
      alp[c - 'a']++;
    if ('A' <= c && c <= 'Z')
      alp[c - 'A']++;
  }

  for (int i = 0; i < ALPHABETS; i++)
    cout << (char)('a' + i) << " : " << alp[i] << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

static const int ALPHABETS = 26;

int main(void) {
  int alp[ALPHABETS] = {0};
  int c;

  do {
    c = getchar();
    if ('a' <= c && c <= 'z')
      alp[c - 'a']++;
    if ('A' <= c && c <= 'Z')
      alp[c - 'A']++;
  } while (c != '.');

  for (int i = 0; i < ALPHABETS; i++)
    cout << (char)('a' + i) << " : " << alp[i] << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  string ch;
  int result[26] = {0};
  while (getline(cin, ch)) {
    for (int i = 0; i < ch.size(); i++) {
      if (isalpha(ch[i])) {
        ch[i] = tolower(ch[i]);
        result[ch[i] - 'a']++;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << (char)('a' + i) << " : " << result[i] << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string ch;
  int result[25] = {0};
  cin >> ch;
  for (int i = 0; i < ch.size(); i++) {
    if (isalpha(ch[i])) {
      result[ch[i] - 'a']++;
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << (char)('a' + i) << " : " << result[i] << endl;
  }
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char ch;
  int count[26] = {0};
  int i;

  while (cin >> ch) {
    if (isalpha(ch) != 0) {
      count[tolower(ch) - 'a']++;
    }
  }
  for (i = 0; i < 26; i++) {
    cout << (char)(i + 'a') << " : " << count[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  char ch;
  int count[26] = {0};
  int i;

  while (1) {
    cin >> ch;
    if (isalpha(ch) != 0) {
      count[tolower(ch) - 'a']++;
    }
  }
  for (i = 0; i < 26; i++) {
    cout << (char)(i + 'a') << " : " << count[i] << endl;
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 1200
using namespace std;

int main() {
  char ch;
  int count[N];

  for (int i = 0; i < 26; i++) {
    count[i] = 0;
  }

  while (cin >> ch) {
    // cin >> ch;
    ch = tolower(ch);
    // if (ch == '.') break;
    if (ch == 'a')
      count[0] += 1;
    else if (ch == 'b')
      count[1] += 1;
    else if (ch == 'c')
      count[2] += 1;
    else if (ch == 'd')
      count[3] += 1;
    else if (ch == 'e')
      count[4] += 1;
    else if (ch == 'f')
      count[5] += 1;
    else if (ch == 'g')
      count[6] += 1;
    else if (ch == 'h')
      count[7] += 1;
    else if (ch == 'i')
      count[8] += 1;
    else if (ch == 'j')
      count[9] += 1;
    else if (ch == 'k')
      count[10] += 1;
    else if (ch == 'l')
      count[11] += 1;
    else if (ch == 'm')
      count[12] += 1;
    else if (ch == 'n')
      count[13] += 1;
    else if (ch == 'o')
      count[14] += 1;
    else if (ch == 'p')
      count[15] += 1;
    else if (ch == 'q')
      count[16] += 1;
    else if (ch == 'r')
      count[17] += 1;
    else if (ch == 's')
      count[18] += 1;
    else if (ch == 't')
      count[19] += 1;
    else if (ch == 'u')
      count[20] += 1;
    else if (ch == 'v')
      count[21] += 1;
    else if (ch == 'w')
      count[22] += 1;
    else if (ch == 'x')
      count[23] += 1;
    else if (ch == 'y')
      count[24] += 1;
    else if (ch == 'z')
      count[25] += 1;
  }

  cout << "a : " << count[0] << endl;
  cout << "b : " << count[1] << endl;
  cout << "c : " << count[2] << endl;
  cout << "d : " << count[3] << endl;
  cout << "e : " << count[4] << endl;
  cout << "f : " << count[5] << endl;
  cout << "g : " << count[6] << endl;
  cout << "h : " << count[7] << endl;
  cout << "i : " << count[8] << endl;
  cout << "j : " << count[9] << endl;
  cout << "k : " << count[10] << endl;
  cout << "l : " << count[11] << endl;
  cout << "m : " << count[12] << endl;
  cout << "n : " << count[13] << endl;
  cout << "o : " << count[14] << endl;
  cout << "p : " << count[15] << endl;
  cout << "q : " << count[16] << endl;
  cout << "r : " << count[17] << endl;
  cout << "s : " << count[18] << endl;
  cout << "t : " << count[19] << endl;
  cout << "u : " << count[20] << endl;
  cout << "v : " << count[21] << endl;
  cout << "w : " << count[22] << endl;
  cout << "x : " << count[23] << endl;
  cout << "y : " << count[24] << endl;
  cout << "z : " << count[25] << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  char ch;
  int counter[26];

  while (1) {
    scanf("%s", &ch);
    ch == tolower(ch);
    if (isalpha(ch))
      counter[ch - 'a']++;
  }

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

  return 0;
}