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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int main() {
  int start, end;
  string s1, s2;
  while (1) {

    cin >> s1;
    if (s1 == ".")
      return 0;
    cin >> s2;
    vector<string> i1(0);
    vector<string> i2(0);
    // s1
    start = 0, end = -1;
    for (int i = 0; i < s1.size(); i++) {
      if (s1[i] == '"') {
        end = max(0, i - 1);
        if (end - start > 0) {
          // cout<<"a:i:"<<i<<" "<<s1.substr(start,end-start+1)<<" "<<endl;
          i1.push_back(s1.substr(start, end - start + 1));
        } else {
          // cout<<"c:i:"<<i<<endl;
          i1.push_back("");
        }
        start = i + 1;
        end = -1;
        // cout<<"start:"<<start<<" end:"<<end<<endl;
      }
      if ((end == -1) and (i == s1.size() - 1)) {
        end = i;
        // cout<<"b:i:"<<i<<" "<<s1.substr(start,end-start+1)<<" "<<endl;
        i1.push_back(s1.substr(start, end - start + 1));
        start = i + 1;
        end = -1;
      }
    }
    // s2
    start = 0, end = -1;
    for (int i = 0; i < s2.size(); i++) {
      if (s2[i] == '"') {
        end = max(0, i - 1);
        if (end - start > 0) {
          i2.push_back(s2.substr(start, end - start + 1));
        } else {
          i2.push_back("");
        }
        start = i + 1;
        end = -1;
      }
      if ((end == -1) and (i == s2.size() - 1)) {
        end = i;
        i2.push_back(s2.substr(start, end - start + 1));
        start = i + 1;
        end = -1;
      }
    }
    int count = 0;
    if (i1.size() != i2.size()) {
      // cout<<"a"<<endl;
      count = 2;
    } else {
      for (int i = 0; i < i1.size(); i++) {
        if (i % 2) {
          if (i1[i] != i2[i]) {
            // cout<<"b"<<endl;
            count++;
          }
        } else {
          // cout<<"c"<<endl;
          if (i1[i] != i2[i]) {
            count = 2;
            break;
          }
        }
      }
    }

    if (count == 0) {
      cout << "IDENTICAL" << endl;
    } else if (count == 1) {
      cout << "CLOSE" << endl;
    } else {
      cout << "DIFFERENT" << endl;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  while (1) {
    int count;
    string n1;
    string n2;
    vector<string> n1s(0);
    vector<string> n2s(0);
    vector<string> n1ns(0);
    vector<string> n2ns(0);
    cin >> n1;
    if (n1 == ".") {
      return 0;
    }
    cin >> n2;
    int l1 = n1.size();
    int l2 = n2.size();

    int start = -1;
    int end = -2;
    for (int i = 0; i < l1; i++) {
      if (n1[i] == '"') {
        if (start == -1) {
          start = i + 1;
          string str = n1.substr(end + 2, start - end - 3);
          n1ns.push_back(str);
        } else {
          end = i - 1;
          string str = n1.substr(start, end - start + 1);
          n1s.push_back(str);
          start = -1;
        }
      }
    }
    if (start == -1) {
      string str = n1.substr(end + 2, l1 - (end + 2));
      n1ns.push_back(str);
    }
    start = -1;
    end = -2;
    for (int i = 0; i < l2; i++) {
      if (n2[i] == '"') {
        if (start == -1) {
          start = i + 1;
          string str = n2.substr(end + 2, start - end - 3);
          n2ns.push_back(str);
        } else {
          end = i - 1;
          string str = n2.substr(start, end - start + 1);
          n2s.push_back(str);
          start = -1;
        }
      }
    }
    if (start == -1) {
      string str = n2.substr(end + 2, l2 - (end + 2));
      n2ns.push_back(str);
    }
    int s1 = n1s.size();
    int s2 = n2s.size();
    int ma = s1 - s2;
    if (ma == 0) {
      count = 0;
      for (int i = 0; i < s1; i++) {
        if (n2s[i] != n1s[i]) {
          count++;
        }
      }
    } else {
      count = -1;
    }
    for (int i = 0; i < n1ns.size(); i++) {
      if (n1ns[i] != n2ns[i])
        count = -1;
    }
    if (count == 1) {
      cout << "CLOSE" << endl;
    } else if (count == 0) {
      cout << "IDENTICIAL" << endl;
    } else {
      cout << "DIFFERENT" << endl;
    }
  }
  return 0;
}