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

#include <cctype>
#include <cstdio>
#include <cstring>
char str[1000000] = {0};
using namespace std;
int main() {
  int f = 0;
  while (scanf("%[^\\n]", str) != EOF) {
    getchar();
    for (int i = 0; i <= 25; i++) {
      for (int j = 0; j < strlen(str); j++) {
        if (str[j] == ' ' || str[j] == '.')
          continue;
        str[j]++;
        if (str[j] > 122)
          str[j] = str[j] - 26;
      }
      for (int j = 0; j < strlen(str); j++) {
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'e')
          goto hoge;
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'i' &&
            str[j + 3] == 's')
          goto hoge;
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'a' &&
            str[j + 3] == 't')
          goto hoge;
      }
    }
    for (int i = 0; i < strlen(str); i++) {
      if (str[i] == ' ' || str[i] == '.')
        continue;
      str[i] -= 25;
    }
    for (int i = 0; i <= 25; i++) {
      for (int j = 0; j < strlen(str); j++) {
        if (str[j] == ' ' || str[j] == '.')
          continue;
        str[j]--;
        if (str[j] < 97)
          str[j] = str[j] + 25;
      }
      for (int j = 0; j < strlen(str); j++) {
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'e')
          goto hoge;
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'i' &&
            str[j + 3] == 's')
          goto hoge;
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'a' &&
            str[j + 3] == 't')
          goto hoge;
      }
    }
  hoge:
    printf("%s\\n", str);
    memset(str, 0, sizeof(str));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
#include <cstring>
char str[1000000] = {0};
using namespace std;
int main() {
  int f = 0;
  while (scanf("%[^\\n]", str) != EOF) {
    fflush(stdin);
    for (int i = 0; i <= 25; i++) {
      for (int j = 0; j < strlen(str); j++) {
        if (str[j] == ' ' || str[j] == '.')
          continue;
        str[j]++;
        if (str[j] > 122)
          str[j] = str[j] - 26;
      }
      for (int j = 0; j < strlen(str); j++) {
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'e')
          goto hoge;
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'i' &&
            str[j + 3] == 's')
          goto hoge;
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'a' &&
            str[j + 3] == 't')
          goto hoge;
      }
    }
    for (int i = 0; i < strlen(str); i++) {
      if (str[i] == ' ' || str[i] == '.')
        continue;
      str[i] -= 25;
    }
    for (int i = 0; i <= 25; i++) {
      for (int j = 0; j < strlen(str); j++) {
        if (str[j] == ' ' || str[j] == '.')
          continue;
        str[j]--;
        if (str[j] < 97)
          str[j] = str[j] + 25;
      }
      for (int j = 0; j < strlen(str); j++) {
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'e')
          goto hoge;
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'i' &&
            str[j + 3] == 's')
          goto hoge;
        if (str[j] == 't' && str[j + 1] == 'h' && str[j + 2] == 'a' &&
            str[j + 3] == 't')
          goto hoge;
      }
    }
  hoge:
    printf("%s\\n", str);
    memset(str, 0, sizeof(str));
  }
  return 0;
}