Problem p00812 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"

int a = 0;
void getspace(string st) {
  while (st[a] == ' ')
    a++;
  return;
}
map<vector<int>, int> getcal(string st);
int getnum(string st) {
  int num = 0;
  // getspace();
  while (isdigit(st[a])) {
    num = num * 10 + st[a] - '0';
    a++;
  }
  return num;
}
pair<char, int> getchar(string st) {
  char ch = st[a];
  a++;
  bool kakeru = false;
  getspace(st);

  int num = 1;
  if (st[a] == '^') {
    a++;
    getspace(st);
    assert(isdigit(st[a]));
    num = getnum(st);
  }
  return make_pair(ch, num);
}

map<vector<int>, int> geta(string st) {
  getspace(st);
  map<vector<int>, int> mp;
  if (isdigit(st[a])) {
    const int num(getnum(st));
    map<vector<int>, int> newmp;
    newmp[vector<int>(26, 0)] = num;
    mp = newmp;
  } else if (isalpha(st[a])) {
    pair<char, int> amp(getchar(st));
    map<vector<int>, int> newmp;
    vector<int> v(26, 0);
    v[amp.first - 'a'] += amp.second;
    newmp[v] = 1;
    mp = newmp;
  } else if (st[a] == '(') {
    a++;
    mp = getcal(st);
    a++;
  } else {
    assert(false);
  }
  while (1) {
    getspace(st);
    if (a == st.size() || st[a] == ')') {
      return mp;
    } else if (st[a] == '(') {
      a++;
      map<vector<int>, int> amp = getcal(st);
      map<vector<int>, int> newmp;
      for (auto a : mp) {
        for (auto b : amp) {
          vector<int> v1(a.first);
          vector<int> v2(b.first);
          transform(v1.begin(), v1.end(), v2.begin(), v1.begin(),
                    [](const int l, const int r) { return l + r; });
          newmp[v1] += a.second * b.second;
        }
      }
      mp = newmp;
      assert(st[a] == ')');
      a++;
    } else if (st[a] == '+') {
      return mp;
    } else if (st[a] == '-') {
      return mp;
    } else if (isdigit(st[a])) {
      const int num(getnum(st));
      map<vector<int>, int> newmp;
      for (const auto m : mp) {
        vector<int> v(m.first);
        newmp[v] = m.second * num;
      }
      mp = newmp;
    } else if (isalpha(st[a])) {
      pair<char, int> amp(getchar(st));
      map<vector<int>, int> newmp;
      for (const auto m : mp) {
        vector<int> v(m.first);
        v[amp.first - 'a'] += amp.second;
        newmp[v] = m.second;
      }
      mp = newmp;
    } else {
      assert(false);
    }
  }
}

map<vector<int>, int> getplmi(string st) {
  map<vector<int>, int> mp(geta(st));
  getspace(st);
  while (1) {
    getspace(st);
    if (a == st.size() || st[a] == ')') {
      return mp;
    }
    if (st[a] == '(') {
      assert(false);
      a++;
      map<vector<int>, int> amp = getcal(st);
      map<vector<int>, int> newmp;
      for (auto a : mp) {
        for (auto b : amp) {
          vector<int> v1(a.first);
          vector<int> v2(b.first);
          transform(v1.begin(), v1.end(), v2.begin(), v2.end(),
                    [](const int l, const int r) { return l + r; });
          newmp[v1] += a.second * b.second;
        }
      }
      mp = newmp;
      assert(st[a] == ')');
      a++;
    } else if (st[a] == '+') {
      return mp;
    } else if (st[a] == '-') {
      return mp;
    } else if (isdigit(st[a])) {
      assert(false);
      const int num(getnum(st));
      map<vector<int>, int> newmp;
      for (const auto m : mp) {
        vector<int> v(m.first);
        newmp[v] = m.second * num;
      }
      mp = newmp;
      a++;
    } else if (isalpha(st[a])) {
      assert(false);
      pair<char, int> amp(getchar(st));
      map<vector<int>, int> newmp;
      for (const auto m : mp) {
        vector<int> v(m.first);
        v[amp.first - 'a'] += amp.second;
        newmp[v] = m.second;
      }
      mp = newmp;
      a++;
    } else {
      assert(false);
    }
  }
}

map<vector<int>, int> getcal(string st) {
  map<vector<int>, int> mp;
  getspace(st);
  mp = getplmi(st);
  while (1) {
    getspace(st);
    if (a == st.size() || st[a] == ')') {
      return mp;
    } else if (st[a] == '+') {
      a++;
      map<vector<int>, int> amp = getplmi(st);
      map<vector<int>, int> newmp(mp);
      for (auto aa : amp) {
        newmp[aa.first] += aa.second;
      }
      mp = newmp;
    } else if (st[a] == '-') {
      a++;
      map<vector<int>, int> amp = getplmi(st);
      map<vector<int>, int> newmp(mp);
      for (auto a : amp) {
        newmp[a.first] -= a.second;
      }
      mp = newmp;
    } else if (isdigit(st[a])) {
      assert(false);
    } else if (isalpha(st[a])) {
      assert(false);
    } else {
      assert(false);
    }
  }
}

map<vector<int>, int> getans(string st) {
  a = 0;
  map<vector<int>, int> prov(getcal(st));
  map<vector<int>, int> ans;
  for (auto p : prov) {
    if (p.second) {
      ans[p.first] = p.second;
    }
  }
  return ans;
}
int main() {
  string st;
  while (1) {
    map<vector<int>, int> ans;
    getline(cin, st);
    if (st == ".") {
      return 0;
    }
    ans = getans(st);

    while (1) {
      getline(cin, st);
      if (st == ".") {
        cout << st << endl;
        break;
      }
      map<vector<int>, int> nans(getans(st));

      if (nans == ans) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}

Error: -6
328f13c3-4411-4571-b7ac-0d863f2861cc.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00812/C++/s149824370.cpp:67: std::map<std::vector<int>, int> geta(std::string): Assertion `false' failed.


Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"

int a = 0;
void getspace(string st) {
  while (st[a] == ' ')
    a++;
  return;
}
map<vector<int>, int> getcal(string st);
int getnum(string st) {
  int num = 0;
  // getspace();
  while (isdigit(st[a])) {
    num = num * 10 + st[a] - '0';
    a++;
  }
  return num;
}
pair<char, int> getchar(string st) {
  char ch = st[a];
  a++;
  bool kakeru = false;
  getspace(st);

  int num = 1;
  if (st[a] == '^') {
    a++;
    getspace(st);
    assert(isdigit(st[a]));
    num = getnum(st);
  }
  return make_pair(ch, num);
}

map<vector<int>, int> geta(string st) {
  getspace(st);
  map<vector<int>, int> mp;
  if (isdigit(st[a])) {
    const int num(getnum(st));
    map<vector<int>, int> newmp;
    newmp[vector<int>(26, 0)] = num;
    mp = newmp;
  } else if (isalpha(st[a])) {
    pair<char, int> amp(getchar(st));
    map<vector<int>, int> newmp;
    vector<int> v(26, 0);
    v[amp.first - 'a'] += amp.second;
    newmp[v] = 1;
    mp = newmp;
  } else if (st[a] == '(') {
    a++;
    mp = getcal(st);
    a++;
  } else {
    assert(false);
  }
  while (1) {
    getspace(st);
    if (a == st.size() || st[a] == ')') {
      return mp;
    } else if (st[a] == '(') {
      a++;
      map<vector<int>, int> amp = getcal(st);
      map<vector<int>, int> newmp;
      for (auto a : mp) {
        for (auto b : amp) {
          vector<int> v1(a.first);
          vector<int> v2(b.first);
          transform(v1.begin(), v1.end(), v2.begin(), v1.begin(),
                    [](const int l, const int r) { return l + r; });
          newmp[v1] += a.second * b.second;
        }
      }
      mp = newmp;
      assert(st[a] == ')');
      a++;
    } else if (st[a] == '+') {
      return mp;
    } else if (st[a] == '-') {
      return mp;
    } else if (isdigit(st[a])) {
      const int num(getnum(st));
      map<vector<int>, int> newmp;
      for (const auto m : mp) {
        vector<int> v(m.first);
        newmp[v] = m.second * num;
      }
      mp = newmp;
    } else if (isalpha(st[a])) {
      pair<char, int> amp(getchar(st));
      map<vector<int>, int> newmp;
      for (const auto m : mp) {
        vector<int> v(m.first);
        v[amp.first - 'a'] += amp.second;
        newmp[v] = m.second;
      }
      mp = newmp;
    } else {
      assert(false);
    }
  }
}

map<vector<int>, int> getplmi(string st) {
  map<vector<int>, int> mp(geta(st));
  getspace(st);
  while (1) {
    getspace(st);
    if (a == st.size() || st[a] == ')') {
      return mp;
    }
    if (st[a] == '(') {
      assert(false);
      a++;
      map<vector<int>, int> amp = getcal(st);
      map<vector<int>, int> newmp;
      for (auto a : mp) {
        for (auto b : amp) {
          vector<int> v1(a.first);
          vector<int> v2(b.first);
          transform(v1.begin(), v1.end(), v2.begin(), v2.end(),
                    [](const int l, const int r) { return l + r; });
          newmp[v1] += a.second * b.second;
        }
      }
      mp = newmp;
      assert(st[a] == ')');
      a++;
    } else if (st[a] == '+') {
      return mp;
    } else if (st[a] == '-') {
      return mp;
    } else if (isdigit(st[a])) {
      assert(false);
      const int num(getnum(st));
      map<vector<int>, int> newmp;
      for (const auto m : mp) {
        vector<int> v(m.first);
        newmp[v] = m.second * num;
      }
      mp = newmp;
      a++;
    } else if (isalpha(st[a])) {
      assert(false);
      pair<char, int> amp(getchar(st));
      map<vector<int>, int> newmp;
      for (const auto m : mp) {
        vector<int> v(m.first);
        v[amp.first - 'a'] += amp.second;
        newmp[v] = m.second;
      }
      mp = newmp;
      a++;
    } else {
      assert(false);
    }
  }
}

map<vector<int>, int> getcal(string st) {
  map<vector<int>, int> mp;
  getspace(st);
  mp = getplmi(st);
  while (1) {
    getspace(st);
    if (a == st.size() || st[a] == ')') {
      return mp;
    } else if (st[a] == '+') {
      a++;
      map<vector<int>, int> amp = getplmi(st);
      map<vector<int>, int> newmp(mp);
      for (auto aa : amp) {
        newmp[aa.first] += aa.second;
      }
      mp = newmp;
    } else if (st[a] == '-') {
      a++;
      map<vector<int>, int> amp = getplmi(st);
      map<vector<int>, int> newmp(mp);
      for (auto a : amp) {
        newmp[a.first] -= a.second;
      }
      mp = newmp;
    } else if (isdigit(st[a])) {
      assert(false);
    } else if (isalpha(st[a])) {
      assert(false);
    } else {
      assert(false);
    }
  }
}

map<vector<int>, int> getans(string st) {
  a = 0;
  map<vector<int>, int> prov(getcal(st));
  map<vector<int>, int> ans;
  for (auto p : prov) {
    if (p.second) {
      ans[p.first] = p.second;
    }
  }
  return ans;
}
int main() {
  string st;
  while (1) {
    map<vector<int>, int> ans;
    getline(cin, st);
    ans = getans(st);
    if (st == ".") {
      return 0;
    }
    while (1) {
      getline(cin, st);
      if (st == ".") {
        cout << st << endl;
        break;
      }
      map<vector<int>, int> nans(getans(st));

      if (nans == ans) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}