Minilek wrote:I'm not sure exactly why I'm getting a compiler error. The judge
seems to have a problem with my declaration of command and prep,
but the program compiles and works fine on my computer (I'm
also using gcc). I've also tried submit-o-matic just in case my email
client was adding in extra weird characters, but still a compile error.
Probably your version of gcc is different from the judge's one. Also compilation flags used by the judge may differ from the defaults gcc uses.
Trying to compile with -pedantic may help finding out possible code errors that a standard compile won't show.
Try to move all declarations before any line of code...
Thanks, I did that and now the solution was accepted. Is this very standard? This is the first time I've come across a compiler where you had to make all declarations before any other code.
Minilek wrote:Thanks, I did that and now the solution was accepted. Is this very standard? This is the first time I've come across a compiler where you had to make all declarations before any other code.
$ gcc -pedantic -o minilek minilek.c
minilek.c: In function `main':
minilek.c:42: warning: ISO C89 forbids mixed declarations and code
minilek.c:52: warning: ISO C89 forbids mixed declarations and code
If you really want to make some declaration local to a piece of code you may wrap it with braces though...
[c]main() {
int i,j,k,x,y,z,n;
scanf("%d",&n);
{
char command[20],prep[20];
for (i=0;i<30;i++) stacks.top = 0;
for (i=0;i<n;i++) push(i,i);
while (1) {
scanf("%s",command);
if (!strcmp(command,"quit")) break;
scanf("%d %s %d",&x,prep,&y);
if (locs[x]==locs[y]) continue;
if (!strcmp(prep,"onto")) while (peek(locs[y])!=y) putback(locs[y]);
if (!strcmp(command,"move")) while (peek(locs[x])!=x) putback(locs[x]);
{
int ind=0,buff[30];
while (peek(locs[x])!=x) buff[ind++] = pop(locs[x]);
buff[ind++] = pop(locs[x]);
for (i=ind-1;i>=0;i--) push(locs[y],buff);
}
}
}
/* ... */[/c]
With this modifications your code should compile fine on the judge.
BTW, it's better if you edit your original code on the board to not show your personal suffix...
struct command
{
int action; //1:move; 2:pile;
int method; //1:onto; 2:over;
int object1,object2;
bool isquit,invalid;
};
struct box b[BOXNUM];
struct box *findtop(struct box *b) //find the topmost box on the stack
{
struct box *currentbox;
currentbox=b;
while(currentbox->up!=0)
{
currentbox=currentbox->up;
}
return currentbox;
}
bool samestack(struct box *box1, struct box *box2) //judge if the two boxes are in the same stack or are the same
{
struct box *currentbox;
currentbox=box1;
while(currentbox!=0)
{
if(currentbox==box2) return true;
currentbox=currentbox->up;
}
currentbox=box1;
while(currentbox!=0)
{
if(currentbox==box2) return true;
currentbox=currentbox->down;
}
return false;
}
struct command getcommand(int num) //return a command structure defined above
{
char act[5];
int cursor;
struct command cmd;
cin>>act;
cmd.invalid=false;
switch(act[0])
{
case 'm': cmd.action=1; break;
case 'p': cmd.action=2; break;
case 'q': cmd.isquit=true; return(cmd);
}
cin>>cmd.object1;
cin>>act;
switch(act[1])
{
case 'n': cmd.method=1; break;
case 'v': cmd.method=2; break;
}
cin>>cmd.object2;
void returnbox(struct box *b) //return the box into its initial position
{
if(b==0) return;
if(b->up!=0) returnbox(b->up);
b->up=0;
b->down->up=0;
b->down=0;
}
struct numInf{
int num;
int pos;
numInf * next;//next 1-2-3-4
numInf * previous;//previous 4-3-2-1
numInf * nextS;//next in the Stack
numInf * previousS;//previous in the Stack
I think that is wrong because dont return some blocks to their initials positions
see
[c]
input :
19
move 1 onto 0
move 0 onto 1
move 0 onto 2
move 2 onto 1
move 4 over 5
move 7 onto 8
move 9 onto 7
move 7 over 9
move 9 over 7
quit
C:\acmuva>gpp -ansi test.cpp
gpp -ansi test.cpp
In file included from c:/djgpp/lang/cxx/3.34/bits/locale_facets.tcc:41,
from c:/djgpp/lang/cxx/3.34/locale:47,
from c:/djgpp/lang/cxx/3.34/bits/ostream.tcc:37,
from c:/djgpp/lang/cxx/3.34/ostream:535,
from c:/djgpp/lang/cxx/3.34/iostream:45,
from test.cpp:1:
c:/djgpp/lang/cxx/3.34/cmath:107: error: `acosf' not declared
c:/djgpp/lang/cxx/3.34/cmath:110: error: `asinf' not declared
c:/djgpp/lang/cxx/3.34/cmath:113: error: `atanf' not declared
c:/djgpp/lang/cxx/3.34/cmath:116: error: `atan2f' not declared
c:/djgpp/lang/cxx/3.34/cmath:119: error: `ceilf' not declared
c:/djgpp/lang/cxx/3.34/cmath:122: error: `coshf' not declared
c:/djgpp/lang/cxx/3.34/cmath:125: error: `expf' not declared
c:/djgpp/lang/cxx/3.34/cmath:128: error: `floorf' not declared
c:/djgpp/lang/cxx/3.34/cmath:131: error: `fmodf' not declared
c:/djgpp/lang/cxx/3.34/cmath:134: error: `frexpf' not declared
c:/djgpp/lang/cxx/3.34/cmath:137: error: `ldexpf' not declared
c:/djgpp/lang/cxx/3.34/cmath:140: error: `logf' not declared
c:/djgpp/lang/cxx/3.34/cmath:143: error: `log10f' not declared
c:/djgpp/lang/cxx/3.34/cmath:146: error: `modff' not declared
c:/djgpp/lang/cxx/3.34/cmath:149: error: `powf' not declared
c:/djgpp/lang/cxx/3.34/cmath:152: error: `sinhf' not declared
c:/djgpp/lang/cxx/3.34/cmath:155: error: `tanf' not declared
c:/djgpp/lang/cxx/3.34/cmath:158: error: `tanhf' not declared
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::acos(float)':
c:/djgpp/lang/cxx/3.34/cmath:184: error: `acosf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::asin(float)':
c:/djgpp/lang/cxx/3.34/cmath:204: error: `asinf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::atan(float)':
c:/djgpp/lang/cxx/3.34/cmath:222: error: `atanf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::atan2(float, float)':
c:/djgpp/lang/cxx/3.34/cmath:240: error: `atan2f' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::ceil(float)':
c:/djgpp/lang/cxx/3.34/cmath:260: error: `ceilf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::cosh(float)':
c:/djgpp/lang/cxx/3.34/cmath:288: error: `coshf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::exp(float)':
c:/djgpp/lang/cxx/3.34/cmath:306: error: `expf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::floor(float)':
c:/djgpp/lang/cxx/3.34/cmath:334: error: `floorf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::fmod(float, float)':
c:/djgpp/lang/cxx/3.34/cmath:352: error: `fmodf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::frexp(float, int*)':
c:/djgpp/lang/cxx/3.34/cmath:372: error: `frexpf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::ldexp(float, int)':
c:/djgpp/lang/cxx/3.34/cmath:391: error: `ldexpf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::log(float)':
c:/djgpp/lang/cxx/3.34/cmath:411: error: `logf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::log10(float)':
c:/djgpp/lang/cxx/3.34/cmath:429: error: `log10f' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::modf(float, float*)':
c:/djgpp/lang/cxx/3.34/cmath:447: error: `modff' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `long double std::modf(long double,
long double*)':
c:/djgpp/lang/cxx/3.34/cmath:461: error: `::modfl' undeclared (first use here)
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::pow(float, float)':
c:/djgpp/lang/cxx/3.34/cmath:486: error: `powf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::sinh(float)':
c:/djgpp/lang/cxx/3.34/cmath:528: error: `sinhf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::tan(float)':
c:/djgpp/lang/cxx/3.34/cmath:556: error: `tanf' undeclared in namespace `
__gnu_cxx::__c99_binding'
c:/djgpp/lang/cxx/3.34/cmath: In function `float std::tanh(float)':
c:/djgpp/lang/cxx/3.34/cmath:574: error: `tanhf' undeclared in namespace `
__gnu_cxx::__c99_binding'