ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1161. Stripies

COMPILATION ERROR in the Array declaration!!!
Posted by Sergio Ligregni 29 Jan 2008 10:16
can you please help me about what is wrong about this?



You tried to solve problem 1161 Stripies.
Your solution was compiled with the following errors:

93e006e3-949c-4a74-a88f-eb4b2c6dc082
93e006e3-949c-4a74-a88f-eb4b2c6dc082(19): error: expression must have a constant value
int set[N];
^

/* why can't I declare a new array like this? (N is integer) */

93e006e3-949c-4a74-a88f-eb4b2c6dc082(61): error: expression must have a constant value
int aux[max-min+1], i=min, k=0;
^

/* The same */

93e006e3-949c-4a74-a88f-eb4b2c6dc082(61): error: expression must have a constant value
int aux[max-min+1], i=min, k=0;
^

/* Two errors on the same line!!! */

compilation aborted for 93e006e3-949c-4a74-a88f-eb4b2c6dc082 (code 2)
Re: COMPILATION ERROR in the Array declaration!!!
Posted by Romko [Lviv NU] 29 Jan 2008 20:22
You couldn't declare array with nonconstant value! In this case try to use dynamic array, or vector.
int aux = new int[N];
or
vector<int> aux(N);
Re: COMPILATION ERROR in the Array declaration!!!
Posted by Sergio Ligregni 30 Jan 2008 10:27
Thaks for helping (I didn´t tried yet)

But... does C (ANSI C, not C++) accept the "vector" type or "int a = new int[10]"???

I have solved dozens of problems using "int a[x];" at UVa online judge, I think there could be more reasonable to forbid the "vector" type using (not elemental) than "int a[x];" (ANSI C elemental array using)

Thanks I hope your reply

Sergio Ligregni, MEX
Re: COMPILATION ERROR in the Array declaration!!!
Posted by Romko [Lviv NU] 31 Jan 2008 01:26
Sorry I've made a mistake...
Not int aux = new int[N];
should be : int * aux = new int[N];

P.S. I don't know how to be with ANSI C, because I've never use it...
P.P.S. I always use vector(or other STL containers).