Page 9 of 11

Re: 727 Equation TLE

Posted: Wed Feb 06, 2013 7:05 pm
by gr81
thanks man, line 63 got problem, somehow '(' was getting poped up because of perced check.fixed it got AC.

Re: 727 - Equation (Runtime Error)

Posted: Thu Feb 14, 2013 9:59 pm
by shuvokr
Please help >> I got RE again and again .....

Code: Select all

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

#define sf scanf
#define pf printf
#define LLU unsigned long long
#define Lu unsigned long
#define LLD long long
#define LD long

int main()
{
    int T = 0, i = 0, cou = 0;
    char c;
    sf("%d", &T);
    getchar();
    getchar();
    while(T--)
    {
        stack <char> st;
        char ans[100000] = {0};
        i = 0;
        cou = 0;
        while(sf("%c", &c) != EOF)
        {
            getchar();
            if(c == '(' || c == '*' || c == '/' || c == '+' || c == '-')
            {
               if(c == '(') cou++;
               if(cou == 0)
               {
                   while(!st.empty())
                   {
                       ans[i++] = st.top();
                       st.pop();
                   }
               }
               st.push(c);
            }
            else if(c == ')')
            {
                while(!st.empty() && st.top() != '(')
                {
                        ans[i++] = st.top();
                        st.pop();
                }
                st.pop();
                cou--;
            }
            else
            {
                ans[i++] = c;
            }
        }
        while(!st.empty())
        {
            ans[i++] = st.top();
            st.pop();
        }
        puts(ans);
    }
    return 0;
}

Re: 727 - Equation (Runtime Error)

Posted: Fri Feb 15, 2013 12:58 am
by lbv
shuvokr wrote:Please help >> I got RE again and again .....
The way you handle the input seems flaky. Have you tried testing an input file with more than one test case?

Check for example:

Input

Code: Select all

2

3

1
+
2
Output

Code: Select all

3

12+

Re: 727 - Equation (Runtime Error)

Posted: Fri Feb 15, 2013 2:45 am
by brianfry713
From uhunt:
AKJ88> Inside [ else if(c == ')') ] you've used [ st.pop() ], what if stack is empty?

Re: 727 - Equation (Runtime Error)

Posted: Sat Feb 16, 2013 4:41 pm
by shuvokr
ibv & brianfry thanks a lot for reply. but i didn't point out my bug... :(
Again and again RE ...
Please help
this is my update code::

Code: Select all

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

#define sf scanf
#define pf printf
#define LLU unsigned long long
#define Lu unsigned long
#define LLD long long
#define LD long

int main()
{
    int T = 0, i = 0, cou = 0, len, j = 0;
    bool ck = true;
    sf("%d", &T);
    getchar();
    while(T--)
    {
        getchar();
        if(!ck) pf("\n");
        ck = false;
        char c;
        stack <char> st;
        char ans[100000] = {0};
        cou = 0;
        while(sf("%c", &c) != EOF)
        {
            getchar();
            if(c == '(' || c == '*' || c == '/' || c == '+' || c == '-')
            {
               if(c == '(') cou++;
               if(cou == 0)
               {
                   while(!st.empty())
                   {
                       ans[j++] = st.top();
                       st.pop();
                   }
               }
               st.push(c);
            }
            else if(c == ')')
            {
                while(st.top() != '(')
                {
                    if(!st.empty())
                      {
                        ans[j++] = st.top();
                        st.pop();
                      }
                }
                if(!st.empty())
                    st.pop();
                cou--;
            }
            else
            {
                ans[j++] = c;
            }
        }
        while(!st.empty())
        {
            ans[j++] = st.top();
            st.pop();
        }
        puts(ans);
        j = 0;
    }
    return 0;
}

Re: 727 - Equation (Runtime Error)

Posted: Sat Feb 16, 2013 6:12 pm
by lbv
shuvokr wrote: Again and again RE ...
Please help
  • Do test your program against an input file with more than one test case. Check the way you handle the input, in particular the blank line between two consecutive cases. I'm not sure about the reason for the RE, but it could be that the input has garbage at the end, so consider that as a possibility.
  • Read carefully what the problem statement says about the precedence of the operators.
Try for example:

Input

Code: Select all

2

2
+
3
*
5

(
(
9
)
)

)
Output

Code: Select all

235*+

9
Notice the extra ')' at the end. As I said, I'm not sure if something like this happens in the judge's data, but it could be one reason why your code produces RE. If your program handles the input robustly, it shouldn't be a problem.

Re: 727 - Equation (Runtime Error)

Posted: Sun Feb 17, 2013 10:20 am
by shuvokr
@lbv Again thanks for reply
Lastly I got AC :D

Re: 727 - Equation (Runtime Error)

Posted: Sun Mar 31, 2013 1:42 pm
by waleed.lutfi
I keep getting WA, although I passed all test cases written here.
Can anyone write more test cases please.

Re: 727 - Equation (Runtime Error)

Posted: Mon Apr 01, 2013 9:42 pm
by brianfry713
You can generate your own at:http://www.uvatoolkit.com/problemssolve.php

Re: 727 - Equation

Posted: Fri Jul 19, 2013 7:37 am
by abcman13
hello all. could one of you help me find the cause of a runtime error with my code? i ran all the test cases on this thread succesfully on my computer (im running windows 7, not quite sure if that's important).

Code: Select all

accepted

Re: 727 - Equation

Posted: Fri Jul 19, 2013 11:56 pm
by brianfry713
On my LINUX machine using g++ your code is stuck in an infinite loop on the sample input.
You can also try http://ideone.com/iZ7L1q
Try changing your input parsing. Maybe check if gets() returns NULL.

Re: 727 - Equation

Posted: Sat Jul 20, 2013 1:19 am
by abcman13
thanks for the help. my code was accepted.

education(runtime error)

Posted: Tue Aug 27, 2013 7:56 pm
by software
Problem no:727
I got RE error but I can not what the problem is in my code.Please help me.

Re: education(runtime error)

Posted: Tue Aug 27, 2013 10:37 pm
by brianfry713
Runtime Error (RE): Your program failed during the execution (segmentation fault, floating point exception...). The exact cause is not reported to the user to avoid hacking. Be sure that your program returns a 0 code to the shell. If you're using Java, please follow all the submission specifications.

727,uva problem

Posted: Tue Aug 27, 2013 11:00 pm
by software
Problem ID:727
Here is my code:
I can not understand why my code get RE .Please help me.
I did not get any reply though I sent another message .