Problem p03289 (C++)

Buggy submission (status: Runtime Error):
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II()                                                                   \
  ({                                                                           \
    int a;                                                                     \
    read(a);                                                                   \
    a;                                                                         \
  })
#define LL()                                                                   \
  ({                                                                           \
    Long a;                                                                    \
    read(a);                                                                   \
    a;                                                                         \
  })
#define DD()                                                                   \
  ({                                                                           \
    double a;                                                                  \
    scanf("%lf", &a);                                                          \
    a;                                                                         \
  })
#define DB if (0)
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); }
template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template <class T> inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-')
      sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar())
    x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}

#define nl puts("")
#define sp printf(" ")
#define phl printf("hello\n")
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63 - __builtin_clzll((x)))
#define MP make_pair
#define FOR(i, x, y) for (vlong i = (x); i <= (y); ++i)
#define ROF(i, x, y) for (vlong i = (y); i >= (x); --i)
#define CLR(x, y) memset(x, y, sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(), (V).end()), (V).end())
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define NUMDIGIT(x, y) (((vlong)(log10((x)) / log10((y)))) + 1)
#define SQ(x) ((x) * (x))
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define FABS(x) ((x) + eps < 0 ? -(x) : (x))
#define ALL(x) (x).begin(), (x).end()
#define LCM(x, y) (((x) / gcd((x), (y))) * (y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x)                                                                \
  if (x >= mod)                                                                \
    x -= mod;
#define MOD(x, y) (((x) * (y)) % mod)
#define ODD(x) (((x)&1) == 0 ? (0) : (1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for (int i = 0; i < n; i++)
#define fogg(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define test                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define endl '\n'
#define off                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)

int main() {
  // #ifndef ONLINE_JUDGE
  //    freopen("input.txt","r",stdin);
  //    freopen("output.txt","w",stdout);
  //    #endif

  string S;
  cin >> S;

  if (S[0] == 'A') {
    int cnt = 0;
    fogg(i, 2, S.size() - 2) {
      if (S[i] == 'C') {
        cnt++;
      }
    }
    if (cnt == 1) {
      bool flag = true;
      rep(i, i < S.size()) {

        if ((S[i] > 'A') && (S[i] <= 'Z') && S[i] != 'C')
          flag = false;
      }
      if (flag) {
        cout << "AC" << endl;
        return 0;
      }
    }
  }
  cout << "WA" << endl;
  return 0;
}


Fixed submission:
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II()                                                                   \
  ({                                                                           \
    int a;                                                                     \
    read(a);                                                                   \
    a;                                                                         \
  })
#define LL()                                                                   \
  ({                                                                           \
    Long a;                                                                    \
    read(a);                                                                   \
    a;                                                                         \
  })
#define DD()                                                                   \
  ({                                                                           \
    double a;                                                                  \
    scanf("%lf", &a);                                                          \
    a;                                                                         \
  })
#define DB if (0)
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); }
template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template <class T> inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-')
      sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar())
    x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}

#define nl puts("")
#define sp printf(" ")
#define phl printf("hello\n")
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63 - __builtin_clzll((x)))
#define MP make_pair
#define FOR(i, x, y) for (vlong i = (x); i <= (y); ++i)
#define ROF(i, x, y) for (vlong i = (y); i >= (x); --i)
#define CLR(x, y) memset(x, y, sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(), (V).end()), (V).end())
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define NUMDIGIT(x, y) (((vlong)(log10((x)) / log10((y)))) + 1)
#define SQ(x) ((x) * (x))
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define FABS(x) ((x) + eps < 0 ? -(x) : (x))
#define ALL(x) (x).begin(), (x).end()
#define LCM(x, y) (((x) / gcd((x), (y))) * (y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x)                                                                \
  if (x >= mod)                                                                \
    x -= mod;
#define MOD(x, y) (((x) * (y)) % mod)
#define ODD(x) (((x)&1) == 0 ? (0) : (1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for (int i = 0; i < n; i++)
#define fogg(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define test                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define endl '\n'
#define off                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)

int main() {
  // #ifndef ONLINE_JUDGE
  //    freopen("input.txt","r",stdin);
  //    freopen("output.txt","w",stdout);
  //    #endif

  string S;
  cin >> S;

  if (S[0] == 'A') {
    int cnt = 0;
    fogg(i, 2, S.size() - 2) {
      if (S[i] == 'C') {
        cnt++;
      }
    }
    if (cnt == 1) {
      bool flag = true;
      rep(i, S.size()) {
        if (S[i] == 'A' || S[i] == 'C') {
          ;
        } else {
          if ((S[i] >= 'A') && (S[i] <= 'Z'))
            flag = false;
        }
      }
      if (flag) {
        cout << "AC" << endl;
        return 0;
      }
    }
  }
  cout << "WA" << endl;
  return 0;
}