Problem p02417 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  char c;
  int count[26] = {0}, a, i;
  while (cin >> c) {
    a = c - 'a';
    if (a < 0) {
      a += 32;
    }
    count[a]++;
  }
  for (i = 0; i < 26; i++) {
    cout << (char)(i + 'a') << " : " << count[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  char ch, 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, 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, aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll, mm, nn, oo,
      pp, qq, rr, ss, tt, uu, vv, ww, xx, yy, zz;
  for (int abc = 0;; abc++) {

    if (ch == '.') {
      break;
    }
    if (ch == a || ch == A) {
      aa += 1;
    } else if (ch == b || ch == B) {
      bb += 1;
    } else if (ch == c || ch == C) {
      cc += 1;
    } else if (ch == d || ch == D) {
      dd += 1;
    } else if (ch == e || ch == E) {
      ee += 1;
    } else if (ch == f || ch == F) {
      ff += 1;
    } else if (ch == g || ch == G) {
      gg += 1;
    } else if (ch == h || ch == H) {
      hh += 1;
    } else if (ch == i || ch == I) {
      ii += 1;
    } else if (ch == j || ch == J) {
      jj += 1;
    } else if (ch == k || ch == K) {
      kk += 1;
    } else if (ch == l || ch == L) {
      ll += 1;
    } else if (ch == m || ch == M) {
      mm += 1;
    } else if (ch == n || ch == N) {
      nn += 1;
    } else if (ch == o || ch == O) {
      oo += 1;
    } else if (ch == p || ch == P) {
      pp += 1;
    } else if (ch == q || ch == Q) {
      qq += 1;
    } else if (ch == r || ch == R) {
      rr += 1;
    } else if (ch == s || ch == S) {
      ss += 1;
    } else if (ch == t || ch == T) {
      tt += 1;
    } else if (ch == u || ch == U) {
      uu += 1;
    } else if (ch == v || ch == V) {
      vv += 1;
    } else if (ch == w || ch == W) {
      ww += 1;
    } else if (ch == x || ch == X) {
      xx += 1;
    } else if (ch == y || ch == Y) {
      yy += 1;
    } else if (ch == z || ch == Z) {
      zz += 1;
    }
  }
  cout << 'a' << " " << ':' << " " << aa << endl;
  cout << 'b' << " " << ':' << " " << bb << endl;
  cout << 'c' << " " << ':' << " " << cc << endl;
  cout << 'd' << " " << ':' << " " << dd << endl;
  cout << 'e' << " " << ':' << " " << ee << endl;
  cout << 'f' << " " << ':' << " " << ff << endl;
  cout << 'g' << " " << ':' << " " << gg << endl;
  cout << 'h' << " " << ':' << " " << hh << endl;
  cout << 'i' << " " << ':' << " " << ii << endl;
  cout << 'j' << " " << ':' << " " << jj << endl;
  cout << 'k' << " " << ':' << " " << kk << endl;
  cout << 'l' << " " << ':' << " " << ll << endl;
  cout << 'm' << " " << ':' << " " << mm << endl;
  cout << 'n' << " " << ':' << " " << nn << endl;
  cout << 'o' << " " << ':' << " " << oo << endl;
  cout << 'p' << " " << ':' << " " << pp << endl;
  cout << 'q' << " " << ':' << " " << qq << endl;
  cout << 'r' << " " << ':' << " " << rr << endl;
  cout << 's' << " " << ':' << " " << ss << endl;
  cout << 't' << " " << ':' << " " << tt << endl;
  cout << 'u' << " " << ':' << " " << uu << endl;
  cout << 'v' << " " << ':' << " " << vv << endl;
  cout << 'w' << " " << ':' << " " << ww << endl;
  cout << 'x' << " " << ':' << " " << xx << endl;
  cout << 'y' << " " << ':' << " " << yy << endl;
  cout << 'z' << " " << ':' << " " << zz << endl;
}