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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef long long LL;

typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
  // std::ofstream ofs("output.txt"); std::cout.rdbuf(ofs.rdbuf());

  while (true) {
    string s1, s2;
    cin >> s1;

    if (s1.length() == 1 && s1 == ".") {
      break;
    }

    cin >> s2;

    // 完全に一致
    if (s1 == s2) {
      cout << "IDENTICAL" << endl;
      continue;
    }

    //""以外をチェック
    {
      vector<string> S1;
      vector<string> S2;

      string tmp = "";
      for (int i = 0; i < s1.size(); i++) {
        if (s1[i] == '"') {
          while (true) {
            i++;
            if (s1[i] == '"') {
              S1.push_back(tmp);
              tmp = "";
              break;
            }
          }
        } else {
          tmp += s1[i];
        }
      }
      if (tmp.size() > 0) {
        S1.push_back(tmp);
      }

      tmp = "";
      for (int i = 0; i < s2.size(); i++) {
        if (s2[i] == '"') {
          while (true) {
            i++;
            if (s2[i] == '"') {
              S2.push_back(tmp);
              tmp = "";
              break;
            }
          }
        } else {
          tmp += s2[i];
        }
      }
      if (tmp.size() > 0) {
        S2.push_back(tmp);
      }

      if (S1.size() != S2.size()) {
        cout << "DIFFERENT" << endl;
        continue;
      } else {
        bool good = true;
        for (int i = 0; i < S1.size(); i++) {
          if (S1[i] != S2[i])
            good = false;
        }
        if (!good) {
          cout << "DIFFERENT" << endl;
          continue;
        }
      }
    }

    //""内をチェック
    {
      vector<string> S1;
      vector<string> S2;

      for (int i = 0; i < s1.size(); i++) {
        string str = "";
        if (s1[i] == '"') {
          while (true) {
            i++;
            if (s1[i] == '"') {
              break;
            }
            str += s1[i];
          }
        }
        S1.push_back(str);
      }
      for (int i = 0; i < s2.size(); i++) {
        string str = "";
        if (s2[i] == '"') {
          while (true) {
            i++;
            if (s2[i] == '"') {
              break;
            }
            str += s2[i];
          }
        }
        S2.push_back(str);
      }

      if (S1.size() != S2.size()) {
        cout << "DIFFERENT" << endl;
      } else {
        int count = 0;
        for (int i = 0; i < S1.size(); i++) {
          if (S1[i] != S2[i])
            count++;
        }

        if (count > 1) {
          cout << "DIFFERENT" << endl;
        } else {
          cout << "CLOSE" << endl;
        }
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef long long LL;

typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
  // std::ofstream ofs("output.txt"); std::cout.rdbuf(ofs.rdbuf());

  while (true) {
    string s1, s2;
    cin >> s1 >> s2;

    if (s1.length() == 1 && s1 == ",") {
      break;
    }

    // 完全に一致
    if (s1 == s2) {
      cout << "IDENTICAL" << endl;
      continue;
    }

    //""以外をチェック
    {
      vector<string> S1;
      vector<string> S2;

      string tmp = "";
      for (int i = 0; i < s1.size(); i++) {
        if (s1[i] == '"') {
          while (true) {
            i++;
            if (s1[i] == '"') {
              S1.push_back(tmp);
              tmp = "";
              break;
            }
          }
        } else {
          tmp += s1[i];
        }
      }
      if (tmp.size() > 0) {
        S1.push_back(tmp);
      }

      tmp = "";
      for (int i = 0; i < s2.size(); i++) {
        if (s2[i] == '"') {
          while (true) {
            i++;
            if (s2[i] == '"') {
              S2.push_back(tmp);
              tmp = "";
              break;
            }
          }
        } else {
          tmp += s2[i];
        }
      }
      if (tmp.size() > 0) {
        S2.push_back(tmp);
      }

      if (S1.size() != S2.size()) {
        cout << "DIFFERENT" << endl;
        continue;
      } else {
        bool good = true;
        for (int i = 0; i < S1.size(); i++) {
          if (S1[i] != S2[i])
            good = false;
        }
        if (!good) {
          cout << "DIFFERENT" << endl;
          continue;
        }
      }
    }

    //""内をチェック
    {
      vector<string> S1;
      vector<string> S2;

      for (int i = 0; i < s1.size(); i++) {
        string str = "";
        if (s1[i] == '"') {
          while (true) {
            i++;
            if (s1[i] == '"') {
              break;
            }
            str += s1[i];
          }
        }
        S1.push_back(str);
      }
      for (int i = 0; i < s2.size(); i++) {
        string str = "";
        if (s2[i] == '"') {
          while (true) {
            i++;
            if (s2[i] == '"') {
              break;
            }
            str += s2[i];
          }
        }
        S2.push_back(str);
      }

      if (S1.size() != S2.size()) {
        cout << "DIFFERENT" << endl;
      } else {
        int count = 0;
        for (int i = 0; i < S1.size(); i++) {
          if (S1[i] != S2[i])
            count++;
        }

        if (count > 1) {
          cout << "DIFFERENT" << endl;
        } else {
          cout << "CLOSE" << endl;
        }
      }
    }
  }
}