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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  /*?????°????????????????????????????????±???
   * ????????§??????????????????????????????(EOF)?????§??\\????????¨??£????????????*/
  int data[2000]; //???????????????????????§0-'a'?????§???????????¨
  REP(i, 2000) data[i] = 0;
  string str;
  while (cin >> str) { /*????????§EOF?????¨???????????????????????????????????§??¬??????
                          ?????????????????§??????k*/
    REP(i, str.size()) {
      int c = str[i];
      if ('a' <= str[i] && str[i] <= 'z')
        data[c]++;
      else if ('A' <= str[i] && str[i] <= 'Z')
        data[c + ('a' - 'A')]++;
    }
  }
  FOR(i, (int)'a', (int)'z' + 1) {
    cout << (char)i << " : " << data[i] << endl;
  }
}

Error: -4

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  /*?????°????????????????????????????????±???
   * ????????§??????????????????????????????(EOF)?????§??\\????????¨??£????????????*/
  int data[100]; //???????????????????????§0-'a'?????§???????????¨
  REP(i, 100) data[i] = 0;
  string str;
  while (cin >> str) { /*????????§EOF?????¨???????????????????????????????????§??¬??????
                          ?????????????????§??????k*/
    REP(i, str.size()) {
      if ('a' <= str[i] && str[i] <= 'z')
        data[(int)str[i]]++;
      else if ('A' <= str[i] && str[i] <= 'Z')
        data[(int)str[i] + ('a' - 'A')]++;
    }
  }
  FOR(i, 'a', 'z') { cout << (char)i << " : " << data[i] << endl; }
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int vowel(char c) {
  if (65 <= c && c <= 90) {
    return (int)c + 32;
  } else if (97 <= c && c <= 122) {
    return (int)c;
  } else {
    return 0;
  }
}

int main() {
  string s;
  int cnt[26];
  for (int i; i < 26; i++) {
    cnt[i] = 0;
  }
  while (getline(cin, s) != 0) {
    for (int i = 0; i < s.length(); i++) {
      int c = vowel(s[i]);
      if (c != 0) {
        int n = c - 97;
        cnt[n]++;
      }
    }
  }
  for (int i; i < 26; i++) {
    cout << (char)(i + 97) << " : " << cnt[i] << "\\n";
  }
}


Error: WA

Fixed submission:

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

using namespace std;

int main() {
  string s;
  getline(cin, s);
  int counter[26];
  for (int i = 0; i < 26; i++) {
    counter[i] = 0;
  }
  for (int i = 0; i < s.length(); i++) {
    int n;
    if (65 <= s[i] <= 90) {
      counter[(int)s[i] - 65]++;
    } else if (97 <= s[i] <= 122) {
      counter[(int)s[i] - 97]++;
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << (char)(i + 65) << " : " << counter[i] << "\\n";
  }
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  int i, j, n, count[100] = {0};
  char ch;
  while (scanf("%c", &ch) != EOF) {
    if (ch >= 'a' && ch <= 'z') {
      count[ch - 'a']++;
    } else if (ch >= 'A' && ch <= 'Z') {
      count[ch - 'A']++;
    }
  }
  for (j = 0; j < 26; j++) {
    printf("%c : %d\\n", j + 'a', count[j]);
  }
  return (0);
}


Error: TLE

Fixed submission:


#include <cstdio>

int main() {
  int count[26];
  for (int i = 0; i < 26; i++) {
    count[i] = 0;
  }
  char s[1200];
  while (fgets(s, 1200, stdin) != NULL) {
    for (int i = 0; i < 26;) {
      if (s[i] == 'a' + 26 || s[i] == 'a' + 26) {
        count[i]++;
      }
    }
    for (int i = 0; i < 26; i++) {
      printf("%c : %d\\n", 'a' + i, count[i]);
    }
  }

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


#include <cstdio>

int main() {
  int count[1201];
  char ch;
  while (scanf("%c", &ch) != EOF) {
    if (ch >= 'a' && ch <= 'z') {
      count[ch - 'a']++;
    } else if (ch >= 'A' && ch <= 'Z') {
      count[ch - 'A']++;
    }
  }
  for (int j = 0; j < 26; j++) {
    printf("%c : %d\\n", j + 'a', count[j]);
  }
  return 0;
}


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


Fixed submission:


#include <cstdio>

int main() {
  int count[26];
  for (int i = 0; i < 1201; i++) {
    count[i] = 0;
  }
  char ch;
  while (scanf("%c", &ch) != EOF) {
    if (ch >= 'a' && ch <= 'z') {
      count[ch - 'a']++;
    } else if (ch >= 'A' && ch <= 'Z') {
      count[ch - 'A']++;
    }
  }
  for (int j = 0; j < 26; j++) {
    printf("%c : %d\\n", j + 'a', count[j]);
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>
#include <vector>

static bool readLines(std::string &str) {
  std::string tmp;

  if (0x00 == &str) {
    return false;
  }

  while (std::getline(std::cin, tmp)) {
    if (0 < tmp.size()) {
      transform(tmp.begin(), tmp.end(), tmp.begin(), tolower);
      str += tmp;
    }
  }

  return true;
}

static bool countAlpha(const std::string &str, std::vector<int> &v) {
  if (0x00 == &str || 0x00 == &v) {
    return false;
  }

  if (0 >= v.size()) {
    v.resize(26);
    for (unsigned int i = 0; i < v.size(); i++) {
      v.at(i) = 0;
    }
  }

  char ch;
  int index = 0;
  for (unsigned int i = 0; i < str.size(); i++) {
    ch = str.at(i);
    if (false == std::isalpha(ch))
      continue;
    index = static_cast<int>(ch - 'a');
    v.at(index)++;
  }

  return true;
}

int main() {
  std::string alpha("abcdefghijklmnopqrstuvwxyz");
  std::string str;
  std::vector<int> vec(26);

  for (unsigned int i = 0; i < vec.size(); i++) {
    vec.at(i) = 0;
  }

  if (true == readLines(str)) {
    countAlpha(str, vec);
    for (unsigned int i = 0; i < vec.size(); i++) {
      std::cout << alpha.at(i) << " : " << vec.at(i) << std::endl;
    }
  }

  return (0);
}

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


Fixed submission:

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>
#include <vector>

static bool readLines(std::string &str) {
  std::string tmp;

  if (0x00 == &str) {
    return false;
  }

  while (std::getline(std::cin, tmp)) {
    if (0 < tmp.size()) {
      transform(str.begin(), str.end(), str.begin(), tolower);
      str += tmp;
    }
  }

  return true;
}

static bool countAlpha(const std::string &str, std::vector<int> &v) {
  if (0x00 == &str || 0x00 == &v) {
    return false;
  }

  if (0 >= v.size()) {
    v.resize(26);
    for (unsigned int i = 0; i < v.size(); i++) {
      v.at(i) = 0;
    }
  }

  char ch;
  int index = 0;
  for (unsigned int i = 0; i < str.size(); i++) {
    ch = str.at(i);
    if (false == std::isalpha(ch))
      continue;
    index = static_cast<int>(ch - 'a');
    v.at(index)++;
  }

  return true;
}

int main() {
  std::string alpha("abcdefghijklmnopqrstuvwxyz");
  std::string str;
  std::vector<int> vec(26);

  for (unsigned int i = 0; i < vec.size(); i++) {
    vec.at(i) = 0;
  }

  if (true == readLines(str)) {
    countAlpha(str, vec);
    for (unsigned int i = 0; i < vec.size(); i++) {
      std::cout << alpha.at(i) << " : " << vec.at(i) << std::endl;
    }
  }

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

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

char ch;
int main() {
  long long count[30] = {0};
  int num;
  while (scanf("%c", &ch) != EOF) {
    if (islower(ch)) {
      num = ch - 'a';
    } else if (isupper(ch)) {
      num = ch - 'A';
    } else {
      continue;
    }
    count[num]++;
  }
  for (int i = 0; i <= 25; i++) {
    printf("%c : %d\\n", 'a' + i, count[i]);
  }
}


Error: 0

Fixed submission:

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

char ch;
int main() {
  long long count[30] = {0};
  while (scanf("%c", &ch) != EOF) {
    if (isalpha(ch)) {
      int num = ch - 'a';
      int num2 = ch - 'A';
      count[num]++;
      count[num2]++;
    }
  }
  for (int i = 0; i <= 25; i++) {
    printf("%c : %d\\n", 'a' + i, count[i]);
  }
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  int alpha[26];
  string sen;
  char abc[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'};
  for (int i = 0; i < 26; i++)
    alpha[i] = 0;

  while (1) {
    getline(cin, sen);
    if (sen.empty())
      break;
    for (int i = 0; i < sen.size(); i++) {
      for (int j = 0; j < 26; j++) {
        if (isupper(sen[i]))
          sen[i] = tolower(sen[i]);
        if (sen[i] == abc[j])
          alpha[abc[j] - 'a']++;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << abc[i] << " : " << alpha[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int alpha[26];
  char sen[1200];
  char abc[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'};
  for (int i = 0; i < 26; i++)
    alpha[i] = 0;
  int counter = 0;
  while (1) {
    scanf("%c", &sen[counter]);
    if (sen[counter] == ' ')
      continue;
    if (sen[counter] == '.')
      break;
    if (counter == 1200)
      break;
    counter++;
  }
  for (int i = 0; i < counter; i++) {
    if (isupper(sen[i]))
      sen[i] = tolower(sen[i]);
    switch (sen[i]) {
    case 'a':
      alpha[0]++;
      break;
    case 'b':
      alpha[1]++;
      break;
    case 'c':
      alpha[2]++;
      break;
    case 'd':
      alpha[3]++;
      break;
    case 'e':
      alpha[4]++;
      break;
    case 'f':
      alpha[5]++;
      break;
    case 'g':
      alpha[6]++;
      break;
    case 'h':
      alpha[7]++;
      break;
    case 'i':
      alpha[8]++;
      break;
    case 'j':
      alpha[9]++;
      break;
    case 'k':
      alpha[10]++;
      break;
    case 'l':
      alpha[11]++;
      break;
    case 'm':
      alpha[12]++;
      break;
    case 'n':
      alpha[13]++;
      break;
    case 'o':
      alpha[14]++;
      break;
    case 'p':
      alpha[15]++;
      break;
    case 'q':
      alpha[16]++;
      break;
    case 'r':
      alpha[17]++;
      break;
    case 's':
      alpha[18]++;
      break;
    case 't':
      alpha[19]++;
      break;
    case 'u':
      alpha[20]++;
      break;
    case 'v':
      alpha[21]++;
      break;
    case 'w':
      alpha[22]++;
      break;
    case 'x':
      alpha[23]++;
      break;
    case 'y':
      alpha[24]++;
      break;
    case 'z':
      alpha[25]++;
      break;
    }
  }

  for (int i = 0; i < 26; i++) {
    cout << abc[i] << " : " << alpha[i] << endl;
  }

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

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

using namespace std;

int main() {
  // your code goes here

  int counts[30] = {0};

  char cs[1201];
  while (scanf("%[^\\n]\\n", cs) != EOF) {
    for (int i = 0; cs[i] != '\\0'; i++) {
      if (isalpha(cs[i])) {
        counts[tolower(cs[i]) - 'a']++;
      }
    }
  }

  for (char c = 'a'; c <= 'z'; c++) {
    printf("%c : %d\\n", c, counts[c - 'a']);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <ctype.h>
#include <iostream>
using namespace std;

int main() {
  char str[1201];
  int ls[26] = {0};

  cin.get(str, 1200);

  for (int i = 0; str[i] != '\\0'; i++)
    if (isalpha(str[i]))
      ls[tolower(str[i]) - 'a']++;

  int character = 0;
  char ch = 'a';
  for (int n : ls) {
    character = int(ch);
    cout << ch << " : " << n << endl;
    character++;
    ch = char(character);
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

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

int main(int argc, const char *argv[]) {
  string sentence;
  int alpha[26] = {0};

  // getline(cin,sentence);
  while (1) {
    getline(cin, sentence);
    for (int i = 0; i < sentence.size(); i++) {
      if (isalpha(sentence[i])) {                   // 文字かどうか判別
        if (isupper(sentence[i])) {                 // 大文字の時↓
          sentence[i] = (char)tolower(sentence[i]); // 小文字を返す
        }
      }
      // cout << sentence[i];
    }
    for (int j = 0; j <= (int)sentence.size(); j++) {
      alpha[sentence[j] - 'a']++; // sentenceに値がある時+する
    }
  }
  for (char ch = 'a'; ch <= 'z'; ch++) {
    cout << ch << " : " << alpha[ch - 'a'] << endl;
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int count[26] = {};
  char ch;

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

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

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  while (1) {

    int count[26] = {};

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

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

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

int main() {
  int z;
  int x[26] = {};
  string ch;
  while (getline(cin, ch)) {
    for (int j = 0; j < (int)ch.size(); j++) {
      if (ch[j] >= 65 && ch[j] <= 90) {
        z = ch[j] - 'A';
        x[z]++;
      } else if (ch[j] >= 97 && ch[j] <= 122) {
        z = ch[j] - 'a';
        x[z]++;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    printf("%c", 97 + i);
    cout << " "
         << ":"
         << " " << x[i] << "\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int z;
  int x[26] = {};
  char ch;
  while ((ch = getchar()) != EOF) {

    if (ch >= 65 && ch <= 90) {
      z = ch - 'A';
      x[z]++;
    } else if (ch >= 97 && ch <= 122) {
      z = ch - 'a';
      x[z]++;
    }
  }
  while (ch != '.')
    ;
  for (int i = 0; i < 26; i++) {
    printf("%c", 97 + i);
    cout << " "
         << ":"
         << " " << x[i] << "\\n";
  }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  string s;
  int a[26] = {};
  while (getline(cin, s) && !s.empty()) {
    REP(i, s.length()) {
      if (s[i] >= 'A' && s[i] <= 'Z')
        a[s[i] - 'A']++;
      else if (s[i] >= 'a' && s[i] <= 'z')
        a[s[i] - 'a']++;
    }
  }
  REP(i, 26) { printf("%c : %d\\n", i + 'a', a[i]); }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  string s;
  int a[26] = {};
  while (getline(cin, s) && !s.empty()) {
    REP(i, s.length()) {
      if (s[i] < 'a')
        a[s[i] - 'A']++;
      else
        a[s[i] - 'a']++;
    }
  }
  REP(i, 26) { printf("%c : %d\\n", i + 'a', a[i]); }
  return 0;
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int alphabet[26];
  for (int i = 0; i < 26; i++)
    alphabet[i] = 0;
  char s;
  while (true) {
    if (scanf("%c", &s) == EOF)
      break;
    else if (65 <= s && s <= 90)
      alphabet[s - 65]++;
    else if (97 <= s && s <= 122)
      alphabet[s - 97]++;
    else
      continue;
  }
  char c = 'a';
  for (int i = 0; i < 26; i++) {
    cout << (char)(c + i) << " : " << alphabet[i] << endl;
  }
}


Error: TLE

Fixed submission:

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

int main(void) {
  int alphabet[26];
  for (int i = 0; i < 26; i++)
    alphabet[i] = 0;
  char s;
  while (true) {
    scanf("%c", &s);
    if (65 <= s && s <= 90)
      alphabet[s - 65]++;
    else if (97 <= s && s <= 122)
      alphabet[s - 97]++;
    else if (s == 46)
      break;
    else
      continue;
  }
  char c = 'a';
  for (int i = 0; i < 26; i++) {

    cout << (char)(c + i) << " : " << alphabet[i] << endl;
  }
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int counter[26];
  char ch;
  for (int i = 0; i < 26; i++) {
    counter[i] = 0;
  }
  while (cin >> ch) {
    if (isalpha(ch)) {
      if (islower(ch))
        counter[ch - 'a']++;
      else
        counter[tolower(ch) - 'a']++;
    }
  }
  for (int i = 0; i < 26; i++) {
    printf("%c : %d\\n", i + 'a', counter[i]);
  }
}


Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
using namespace std;
int main() {
  int counter[25];
  char ch;
  for (int i = 0; i < 25; i++) {
    counter[i] = 0;
  }
  while (scanf("%c", ch) != EOF) {
    counter[ch - 'a']++;
  }
  for (int i = 0; i < 25; i++) {
    printf("%c : %d\\n", i, counter[i]);
  }
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int charcount[26] = {0}, num;
  char ch;

  while (scanf("%c", &ch) != EOF) {
    if (ch <= 'Z' && ch >= 'A')
      ch += 'a' - 'A';
    if (ch <= 'z' && ch >= 'a')
      charcount[ch - 'a']++;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

#include <cctype>
#include <cstdio>
int main() {
  int n[26] = {0};
  char c;
  while (scanf("%c", &c) != EOF)
    n[(int)tolower(c) - 97]++;
  for (int i = 0; i < 26; i++)
    printf("%c : %d\\n", i + 97, n[i]);
}

Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
int main() {
  int n[26] = {0};
  char c;
  while (scanf("%c", &c))
    n[(int)tolower(c) - 97]++;
  c = 97;
  for (int i = 0; i < 26; i++)
    printf("%c : %d\\n", c + i, n[i]);
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
int main() {
  int n[26] = {0};
  char c;
  while (scanf("%c", &c) != EOF)
    n[(int)tolower(c) - 97]++;
  c = 97;
  for (int i = 0; i < 26; i++)
    printf("%c : %d\\n", c + i, n[i]);
}

Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
int main() {
  int n[26] = {0};
  char c;
  while (scanf("%c", &c), c != EOF)
    n[(int)tolower(c) - 97]++;
  c = 97;
  for (int i = 0; i < 26; i++)
    printf("%c : %d\\n", c + i, n[i]);
}
Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string word;          // string型直接代入できる
  char alp[26] = {0};   // a~z
  int result[26] = {0}; // 0~25
  int n;

  // alpにアルファベット格納する
  for (int i = 97; i <= 122; i++) {
    alp[i - 97] = i;
  }

  while (getline(cin, word)) // getline:空白が入ってても1行分読み込める
  {
    // 入力
    for (int i = 0; i < word.length(); i++) {
      if (word[i] >= 'A' && word[i] <= 'Z') {
        n = word[i] - 'A';
        result[n]++;
      }
      if (word[i] >= 'a' && word[i] <= 'z') {
        n = word[i] - 'a';
        result[n]++;
      }
    }
  }
  // 出力
  for (int k = 0; k < 26; k++) {
    cout << alp[k] << " "
         << ":"
         << " " << result[k] << "\\n";
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  string word;          // string型直接代入できる
  char alp[26] = {0};   // a~z
  int result[26] = {0}; // 0~25
  int n;

  // alpにアルファベット格納する
  for (int i = 97; i <= 122; i++) {
    alp[i - 97] = i;
  }

  while (1) {
    getline(cin, word); // 空白が入ってても1行分読み込める

    // 入力
    for (int i = 0; i < word.length(); i++) {
      if (word[i] >= 'A' && word[i] <= 'Z') {
        n = word[i] - 'A';
        if (n >= 0 && n <= 25)
          result[n]++;
      }
      if (word[i] >= 'a' && word[i] <= 'z') {
        n = word[i] - 'a';
        if (n >= 0 && n <= 25)
          result[n]++;
      }
    }
  }
  // 出力
  for (int k = 0; k < 26; k++) {
    cout << alp[k] << " "
         << ":"
         << " " << result[k] << "\\n";
  }
  return 0;
}