10875 - Big Math

All about problems in Volume 108. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

james299
New poster
Posts: 10
Joined: Tue Jul 26, 2005 8:58 am
Location: Taiwan

Post 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:
Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

Post 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.
Some Love Stories Live Forever ....
james299
New poster
Posts: 10
Joined: Tue Jul 26, 2005 8:58 am
Location: Taiwan

Post 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:
Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

<>

Post 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.
Some Love Stories Live Forever ....
james299
New poster
Posts: 10
Joined: Tue Jul 26, 2005 8:58 am
Location: Taiwan

Post 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. :)
Nazmul Quader Zinnuree
New poster
Posts: 42
Joined: Sun Jul 31, 2005 2:07 am
Location: SUST. Bangladesh
Contact:

10875 WA WA WA ....

Post by Nazmul Quader Zinnuree »

Code: Select all

Cut it of
[/code]
Last edited by Nazmul Quader Zinnuree on Fri Aug 19, 2005 11:38 am, edited 1 time in total.
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

Post 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
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 10875 WA WA WA ....

Post 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.
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post 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?
Nazmul Quader Zinnuree
New poster
Posts: 42
Joined: Sun Jul 31, 2005 2:07 am
Location: SUST. Bangladesh
Contact:

Post by Nazmul Quader Zinnuree »

Thanks Martin, You ARE great....
AC now....
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

Post by sunnycare »

still wa... :cry:
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post 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
bafu
New poster
Posts: 2
Joined: Sat Jul 10, 2004 5:49 pm
Location: Taiwan

Re: 10875 - Big Math

Post 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?
Post Reply

Return to “Volume 108 (10800-10899)”