Problem p00088 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
#define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--)
#define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--)
#define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define vrep(i, c)                                                             \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template <class T, class S> inline bool minup(T &m, S x) {
  return m > (T)x ? (m = (T)x, true) : false;
}
template <class T, class S> inline bool maxup(T &m, S x) {
  return m < (T)x ? (m = (T)x, true) : false;
}

const int INF = 1000000000;
const ll MOD = 1000000007LL;
const double EPS = 1E-12;

map<char, string> en;
map<string, string> de;
string s, t;
string in;
int n;

void encode() {
  en[' '] = "101";
  en['\''] = "000000";
  en[','] = "000011";
  en['-'] = "10010001";
  en['.'] = "010001";
  en['?'] = "000001";
  en['A'] = "100101";
  en['B'] = "10011010";
  en['C'] = "0101";
  en['D'] = "0001";
  en['E'] = "110";
  en['F'] = "01001";
  en['G'] = "10011011";
  en['H'] = "010000";
  en['I'] = "0111";
  en['J'] = "10011000";
  en['K'] = "0110";
  en['L'] = "00100";
  en['M'] = "10011001";
  en['N'] = "10011110";
  en['O'] = "00101";
  en['P'] = "111";
  en['Q'] = "10011111";
  en['R'] = "1000";
  en['S'] = "00110";
  en['T'] = "00111";
  en['U'] = "10011100";
  en['V'] = "10011101";
  en['W'] = "000010";
  en['X'] = "10010010";
  en['Y'] = "10010011";
  en['Z'] = "10010000";
}

void decode() {
  de["00000"] = "A";
  de["00001"] = "B";
  de["00010"] = "C";
  de["00011"] = "D";
  de["00100"] = "E";
  de["00101"] = "F";
  de["00110"] = "G";
  de["00111"] = "H";
  de["01000"] = "I";
  de["01001"] = "J";
  de["01010"] = "K";
  de["01011"] = "L";
  de["01100"] = "M";
  de["01101"] = "N";
  de["01110"] = "O";
  de["01111"] = "P";
  de["10000"] = "Q";
  de["10001"] = "R";
  de["10010"] = "S";
  de["10011"] = "T";
  de["10100"] = "U";
  de["10101"] = "V";
  de["10110"] = "W";
  de["10111"] = "X";
  de["11000"] = "Y";
  de["11001"] = "Z";
  de["11010"] = " ";
  de["11011"] = ".";
  de["11100"] = ",";
  de["11101"] = "-";
  de["11110"] = "'";
  de["11111"] = "?";
}

int main() {
  encode();
  decode();

  while (getline(cin, s)) {
    in += s + " ";

    rep(i, in.size() - 1) t += en[in[i]];
    n = (5 - t.size() % 5) % 5;
    rep(i, n) t += "0";

    n = t.size() / 5;
    rep(i, n) cout << de[t.substr(5 * i, 5)];
    cout << endl;
  }

  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
#define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--)
#define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--)
#define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define vrep(i, c)                                                             \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template <class T, class S> inline bool minup(T &m, S x) {
  return m > (T)x ? (m = (T)x, true) : false;
}
template <class T, class S> inline bool maxup(T &m, S x) {
  return m < (T)x ? (m = (T)x, true) : false;
}

const int INF = 1000000000;
const ll MOD = 1000000007LL;
const double EPS = 1E-12;

map<char, string> en;
map<string, string> de;
string s, t;
string in;
int n;

void encode() {
  en[' '] = "101";
  en['\''] = "000000";
  en[','] = "000011";
  en['-'] = "10010001";
  en['.'] = "010001";
  en['?'] = "000001";
  en['A'] = "100101";
  en['B'] = "10011010";
  en['C'] = "0101";
  en['D'] = "0001";
  en['E'] = "110";
  en['F'] = "01001";
  en['G'] = "10011011";
  en['H'] = "010000";
  en['I'] = "0111";
  en['J'] = "10011000";
  en['K'] = "0110";
  en['L'] = "00100";
  en['M'] = "10011001";
  en['N'] = "10011110";
  en['O'] = "00101";
  en['P'] = "111";
  en['Q'] = "10011111";
  en['R'] = "1000";
  en['S'] = "00110";
  en['T'] = "00111";
  en['U'] = "10011100";
  en['V'] = "10011101";
  en['W'] = "000010";
  en['X'] = "10010010";
  en['Y'] = "10010011";
  en['Z'] = "10010000";
}

void decode() {
  de["00000"] = "A";
  de["00001"] = "B";
  de["00010"] = "C";
  de["00011"] = "D";
  de["00100"] = "E";
  de["00101"] = "F";
  de["00110"] = "G";
  de["00111"] = "H";
  de["01000"] = "I";
  de["01001"] = "J";
  de["01010"] = "K";
  de["01011"] = "L";
  de["01100"] = "M";
  de["01101"] = "N";
  de["01110"] = "O";
  de["01111"] = "P";
  de["10000"] = "Q";
  de["10001"] = "R";
  de["10010"] = "S";
  de["10011"] = "T";
  de["10100"] = "U";
  de["10101"] = "V";
  de["10110"] = "W";
  de["10111"] = "X";
  de["11000"] = "Y";
  de["11001"] = "Z";
  de["11010"] = " ";
  de["11011"] = ".";
  de["11100"] = ",";
  de["11101"] = "-";
  de["11110"] = "'";
  de["11111"] = "?";
}

int main() {
  encode();
  decode();

  while (getline(cin, s)) {
    t = "";
    in = "";
    in += s + " ";

    rep(i, in.size() - 1) t += en[in[i]];
    n = (5 - t.size() % 5) % 5;
    rep(i, n) t += "0";

    n = t.size() / 5;
    rep(i, n) cout << de[t.substr(5 * i, 5)];
    cout << endl;
  }

  return 0;
}