SIGABRT ERROR

Hi i am getting sigabrt error for this problem on codechef.Please help anyone.

Here's the question.

https://www.codechef.com/LOCJUN18/problems/LOC18JUN

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
 
#include <bits/stdc++.h>
using namespace std;

int main() {
    int left, right, pos;
    char c;
    int n;
    int q;
    cin >> n;
    string s[n];
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    cin >> q;
    int ans = 0;
    for (int i = 0; i < q; ++i) {
        ans = 0;
        cin >> left >> right >> pos >> c;
        for (int j = left - 1; j < right; ++j) {
            if (s[j].length() >= pos - 1) {
                if (s[j].at(pos - 1) == c) {
                    ++ans;
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}
Last edited on
Hey can anyone please help me with this ??
Thanks.
@Wasp

The step you're trying to do on line 11, is illegal. You can, though, create the array, using new.

Here's an example program..
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
57
58
59
60
61
62
#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

void bubble(string s[], int);
void list(string s[], int);


int main()
{
	int SIZE, i;
	cout << endl << "MaxSize for the array, to equal what ? : ";
	cin >> SIZE;
	string* s = new string[SIZE];

	cout << "Enter " << SIZE << " different words, one at a time.." << endl;
	for (i = 0; i < SIZE; i++)
	{
		cin >> s[i];
	}

	cout << "Data in original order:" << endl;
	list(s, SIZE);

	bubble(s, SIZE);

	cout << "\nData in ascending order:" << endl;
	list(s, SIZE);

	delete[] s;
}


void list(string s[], int SIZE)
{
	cout << "The words entered, were.." << endl;
	for (int i = 0; i < SIZE; ++i)
	{
		cout << s[i] << endl;
	}
}

void bubble(string s[], int SIZE)
{
	string place;
	for (int move_n = 1; move_n < SIZE; ++move_n)
	{
		for (int i = 0; i < SIZE - 1; ++i)
		{
			if (s[i] > s[i + 1])
			{
				place = s[i];
				s[i] = s[i + 1];
				s[i + 1] = place;
			}
		}
	}
}
Why don't you use a vector of strings ?
@whitenite1 whats wrong in line 11
@Wasp

Most compilers do not allow the creation of arrays at run time. They need to allot memory space for them at the time of compiling. I guess there can be a few compilers that will allow it, but not many, I'm sure.
@Wasp
can you tell the idea of how to do 2nd question of this challenge
https://www.codechef.com/LOCJUN18/problems/CHEFCUP
is the formula we have to apply is this:-
volume = x*(A-x)*(B-x)
and then after differentiating it and put this equation equal to zero to find the value of x so that the volume can be maximised.
is this approach is correct?
@zyan1zyan yes it is correct can you tell me how to go for 3rd question?
@all has anyone got solution to SIGABRT error
@zyan1zyan it gives TLE for 2nd question using 1st derivative principle
@Wasp , use vector of strings, I tried it, It will only pass the first task, giving 30 points, gives TLE in 2nd task..
Topic archived. No new replies allowed.