SIGSEGV on codechef

When I run the following code it works fine on my Windows PC under Code::Blocks 17.12, but I get a SIGSEGV on codechef. What's wrong

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>

using namespace std;

inline bool contains(const char *haystack)
{
  int cnt_c = 0, cnt_e = 0, cnt_f = 0, cnt_h = 0;

  for (size_t i = 0; i < 4; ++i)
  {
    switch (haystack[i])
    {
      case 'c': cnt_c++; break;
      case 'e': cnt_e++; break;
      case 'f': cnt_f++; break;
      case 'h': cnt_h++; break;
      default: return false;
    }
  }
  return cnt_c == 1 && cnt_e == 1 && cnt_f == 1 && cnt_h == 1;

}


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int num_tests;
  cin >> num_tests;
  cin.ignore(255, '\n');
  string input;
  input.reserve(500000);

  while(num_tests--)
  {
    cin >> input;
    size_t size = input.size(), count = 0;
    for (size_t i = 0; i < size - 3; ++i)
    {
      if (contains(&input[i]))
      {
         ++count;
      }
    }
    if (count)
    {
      cout << "Lovely " << count << endl;
    }
    else
    {
      cout << "Normal" << endl;
    }
  }
}

The task it at https://www.codechef.com/problems/CHEFCHR#
What are your inputs? If the length is less than 3 characters, you're in trouble.
Thanks, I added the check for the size and it solved the SIGSEGV problem.
Topic archived. No new replies allowed.