Page 2 of 2

Posted: Fri Jul 29, 2005 2:56 am
by james299
Thanks for your reply :D
Have u check this type of input. Like 0-2 = -2, i mean start with 0 but not only have one digit. 0 follows with some operation.
I didn't, now I correct this error in my code.
2. And for each case I can sure no extra space at each end of line.
But I removed the last space of my output, so it is a wrong ouput. I have made a adjustment in this.

But I still got WA.
Please help me to find out the bug ,or some critical I/O is appreciated.
:wink:

Posted: Fri Jul 29, 2005 6:34 am
by Raj Ariyan
Hi James,
I think it'll better if u share your process with us or you can send your code by pm. Another things, in this type of problem, in my opinion, if u writing n'th line code then u must be sure that 1 to n-1 lines are perfect and bug free. I mean for proceed one line u have to sure that upto this line alls code are error free. Good luck.

Posted: Fri Jul 29, 2005 3:50 pm
by james299
Hi! Raj Ariyan
Raj Ariyan said :
in this type of problem, in my opinion, if u writing n'th line code then u must be sure that 1 to n-1 lines are perfect and bug free. I mean for proceed one line u have to sure that upto this line alls code are error free.
Thanks for your suggestion.
So I try to rewrite my code ,and a very stupid thing I find out.
000
0..
000
0.0
000
In this case my code can't print number 6. :oops:
So I test every separate fucntion ensure that every part is Bug free, as you told me. :wink:
Thank you again . :lol:

Now I got runtime error instead of wrong answer. And now the registeration system isn't available, so I can't change the option to receive the mail which includes the error message. :cry:

<>

Posted: Fri Jul 29, 2005 4:12 pm
by Raj Ariyan
Hi James,
You didnt mention which RTE u get. I dont think that u got SIGFPE(floating point exception), bcoz the problem statement cleary says that "there are no divide-by-zero errors". Most probably segment violation. So, check invalid memory access. For ur kind information, i use num[20] for operands and for taking input line in[1000]. Hope it helps. Good luck.

Posted: Fri Jul 29, 2005 4:57 pm
by james299
Hi ! Raj Ariyan

Actually! I really don't have any clue about what's wrong with it.
The only information I got is "Runtime Error" without showing "SIGSEGV"(NullPointerException) or "SIGFPE"(FloatingPointException)

BTW, my size for operators is 50 ,for numbers is 1000.
And I do some assert to make sure never divid by zero.

I guess the only possiblity for exception occurs is equation computing.
I use linklist to push the input data.

Code: Select all

void addtwo(compute *top , char O ,long long  int V) {
     /* 
     except first one , I read input in pair.
     */
     compute *temp = top ;
     compute *newNodeO = (compute *) malloc(sizeof(compute));
     compute *newNodeV = (compute *) malloc(sizeof(compute));
     newNodeO->operation = O;
     newNodeO->next = newNodeV;
     newNodeV->prev = newNodeO;
     newNodeV->next = NULL ;
     newNodeV->Value = V;
     while(temp->next!=NULL)
     temp = temp->next;
     temp->next = newNodeO;
     newNodeO->prev = temp;
     }
Except the first one input, the rest of input are in the form of (operator)+(Vlaue).

Code: Select all

void calculate(compute *top ,int n) {
     compute *temp = top ;
     /* 
     first check this node is an operator or not. 
     if it is, I compute result in the form of ( Num1 Operator Num2 )
     I use linklist to meet the priority requirements
     int n is a indicator for the priorities 
     n == mudi 1 means mutiply and divid
     n == plmi 0 means plus and minus
     I use two times fuction calculate() per equation 
     */
     while(temp!=NULL) { 
       if(temp->operation=='*'||temp->operation=='+'||temp->operation=='-'||temp->operation=='/')   {                                                                               
       if(temp->next!=NULL&&temp->prev!=NULL)/*just in case*/
      if(n==mudi)  {                  
        if(temp->operation=='*')  {
      temp->prev->Value = temp->prev->Value * temp->next->Value;
        ToNext()
      }
        else if(temp->operation=='/') {
      temp->prev->Value = temp->prev->Value / temp->next->Value;  
         ToNext()
         }   
      }/*if*/
      else {
       if(temp->operation=='+') {
      temp->prev->Value = temp->prev->Value + temp->next->Value;
         ToNext()
         }      
       else if(temp->operation=='-') {
      temp->prev->Value = temp->prev->Value - temp->next->Value;
         ToNext()
         }
      }/*else */
      
      }/* is operator */
      temp = temp->next;
      }/*while*/
}
I add some comment hope it could help :wink:
ToNext() is a macro which I use to make my code readable.
It's designed for to-next. When priority and operator is matched ,I get rid of second and third node, and point to fourth (if there is),continue the process untill all work are finished.
Detail as follow:

Code: Select all

#define ToNext() \
            if(temp!=NULL&&temp->next!=NULL) \
      temp->prev->next = temp->next->next; \
      if(temp!=NULL&&temp->next!=NULL&&temp->next->next!=NULL) \
      temp->next->next->prev = temp->prev; \
      temp = temp->prev; 
I am not good at pointer management ,as you see above :o
And I do understand it's a great pain to read other people's code ,espcially those ugly code.
I don't think my coding sytle is good enough for other to catch easily.
But it's not helpful when I need help and other gets less information. :wink:
So it's final step for me. Or I can send you my code for you to test. 8)

Thanks for your precious time. :)

10875 WA WA WA ....

Posted: Fri Aug 19, 2005 8:14 am
by Nazmul Quader Zinnuree

Code: Select all

Cut it of
[/code]

Posted: Fri Aug 19, 2005 10:30 am
by sunnycare
i get WA too,i also need help .

i think this input is invalid

Code: Select all

... .0. 000 000 
... .0. ..0 0.0 
000 .0. 000 000 
... .0. 0.. 0.0 
... .0. 000 000 
because the problem said

Re: 10875 WA WA WA ....

Posted: Fri Aug 19, 2005 10:56 am
by Martin Macko
Check this line:
Nazmul Quader Zinnuree wrote:

Code: Select all

		else if (!strcmp(temp[0], "...") && !strcmp(temp[1], ".0.") && !strcmp(temp[2], "000") && !strcmp(temp[3], ".0.") && !strcmp(temp[4], "..."))
			ex[i / 4] = '+';
Problem Statement wrote:

Code: Select all

000 .0. 000 000 0.0 000 0.. 000 000 000 .0. ... 0.0 .0.
0.0 .0. ..0 ..0 0.0 0.. 0.. ..0 0.0 0.0 .0. ... 0.0 ...
0.0 .0. 000 000 000 000 000 ..0 000 000 000 000 .0. 000
0.0 .0. 0.. ..0 ..0 ..0 0.0 ..0 0.0 ..0 .0. ... 0.0 ...
000 .0. 000 000 ..0 000 000 ..0 000 ..0 .0. ... 0.0 .0.

Posted: Fri Aug 19, 2005 11:03 am
by Martin Macko
sunnycare wrote:i think this input is invalid

Code: Select all

... .0. 000 000 
... .0. ..0 0.0 
000 .0. 000 000 
... .0. 0.. 0.0 
... .0. 000 000 
Yes, it is invalid input.

For inputs and hints see other topics on this problem: http://online-judge.uva.es/board/viewtopic.php?t=8403, http://online-judge.uva.es/board/viewtopic.php?t=8498, http://online-judge.uva.es/board/viewtopic.php?t=8400.

Why do people always create new topics on a problem if there are alerady plenty of them?

Posted: Fri Aug 19, 2005 11:43 am
by Nazmul Quader Zinnuree
Thanks Martin, You ARE great....
AC now....

Posted: Fri Aug 19, 2005 12:49 pm
by sunnycare
still wa... :cry:

Posted: Fri Aug 19, 2005 12:54 pm
by Martin Macko
sunnycare wrote:still wa... :cry:
well, if nothing helps, post your code here.... but first check all issues mentioned in all topics on this problem

Re: 10875 - Big Math

Posted: Fri Feb 13, 2015 10:35 am
by bafu
I suspect that the testing data does not follow this condition in the problem description:
the intermediate and final results will fit in a 32-bit signed integer.
After I increased the size of the variables used to store intermediate and final results from int to long long, I got AC. Does there anyone meet the same situation as mine?