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

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

int main() {
  string a;
  int b[26] = {};
  while (cin >> a) {
    for (int i = 0; i < 1200; i++) {
      if (a[i] == 'a' || a[i] == 'A')
        b[0]++;
      else if (a[i] == 'b' || a[i] == 'B')
        b[1]++;
      else if (a[i] == 'c' || a[i] == 'C')
        b[2]++;
      else if (a[i] == 'd' || a[i] == 'D')
        b[3]++;
      else if (a[i] == 'e' || a[i] == 'E')
        b[4]++;
      else if (a[i] == 'f' || a[i] == 'F')
        b[5]++;
      else if (a[i] == 'g' || a[i] == 'G')
        b[6]++;
      else if (a[i] == 'h' || a[i] == 'H')
        b[7]++;
      else if (a[i] == 'i' || a[i] == 'I')
        b[8]++;
      else if (a[i] == 'j' || a[i] == 'J')
        b[9]++;
      else if (a[i] == 'k' || a[i] == 'K')
        b[10]++;
      else if (a[i] == 'l' || a[i] == 'L')
        b[11]++;
      else if (a[i] == 'm' || a[i] == 'M')
        b[12]++;
      else if (a[i] == 'n' || a[i] == 'N')
        b[13]++;
      else if (a[i] == 'o' || a[i] == 'O')
        b[14]++;
      else if (a[i] == 'p' || a[i] == 'P')
        b[15]++;
      else if (a[i] == 'q' || a[i] == 'Q')
        b[16]++;
      else if (a[i] == 'r' || a[i] == 'R')
        b[17]++;
      else if (a[i] == 's' || a[i] == 'S')
        b[18]++;
      else if (a[i] == 't' || a[i] == 'T')
        b[19]++;
      else if (a[i] == 'u' || a[i] == 'U')
        b[20]++;
      else if (a[i] == 'v' || a[i] == 'V')
        b[21]++;
      else if (a[i] == 'w' || a[i] == 'W')
        b[22]++;
      else if (a[i] == 'x' || a[i] == 'X')
        b[23]++;
      else if (a[i] == 'y' || a[i] == 'Y')
        b[24]++;
      else if (a[i] == 'z' || a[i] == 'Z')
        b[25]++;
      else if (!a[i])
        break;
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:


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

int main() {

  string a;
  int b[26] = {};
  int check = 1;
  do {
    cin >> a;

    for (int i = 0; i < 1200; i++) {
      if (a[i] == 'a' || a[i] == 'A')
        b[0]++;
      else if (a[i] == 'b' || a[i] == 'B')
        b[1]++;
      else if (a[i] == 'c' || a[i] == 'C')
        b[2]++;
      else if (a[i] == 'd' || a[i] == 'D')
        b[3]++;
      else if (a[i] == 'e' || a[i] == 'E')
        b[4]++;
      else if (a[i] == 'f' || a[i] == 'F')
        b[5]++;
      else if (a[i] == 'g' || a[i] == 'G')
        b[6]++;
      else if (a[i] == 'h' || a[i] == 'H')
        b[7]++;
      else if (a[i] == 'i' || a[i] == 'I')
        b[8]++;
      else if (a[i] == 'j' || a[i] == 'J')
        b[9]++;
      else if (a[i] == 'k' || a[i] == 'K')
        b[10]++;
      else if (a[i] == 'l' || a[i] == 'L')
        b[11]++;
      else if (a[i] == 'm' || a[i] == 'M')
        b[12]++;
      else if (a[i] == 'n' || a[i] == 'N')
        b[13]++;
      else if (a[i] == 'o' || a[i] == 'O')
        b[14]++;
      else if (a[i] == 'p' || a[i] == 'P')
        b[15]++;
      else if (a[i] == 'q' || a[i] == 'Q')
        b[16]++;
      else if (a[i] == 'r' || a[i] == 'R')
        b[17]++;
      else if (a[i] == 's' || a[i] == 'S')
        b[18]++;
      else if (a[i] == 't' || a[i] == 'T')
        b[19]++;
      else if (a[i] == 'u' || a[i] == 'U')
        b[20]++;
      else if (a[i] == 'v' || a[i] == 'V')
        b[21]++;
      else if (a[i] == 'w' || a[i] == 'W')
        b[22]++;
      else if (a[i] == 'x' || a[i] == 'X')
        b[23]++;
      else if (a[i] == 'y' || a[i] == 'Y')
        b[24]++;
      else if (a[i] == 'z' || a[i] == 'Z')
        b[25]++;
      else if (!a[i])
        break;
      else if (a[i] == '.')
        check = 0;
    }

  } while (check);

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

  return 0;
}