727 - Equation
Moderator: Board moderators
Re: 727 Equation TLE
thanks man, line 63 got problem, somehow '(' was getting poped up because of perced check.fixed it got AC.
Re: 727 - Equation (Runtime Error)
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;
}
Code: Select all
enjoying life .....
Re: 727 - Equation (Runtime Error)
The way you handle the input seems flaky. Have you tried testing an input file with more than one test case?shuvokr wrote:Please help >> I got RE again and again .....
Check for example:
Input
Code: Select all
2
3
1
+
2
Code: Select all
3
12+
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 727 - Equation (Runtime Error)
From uhunt:
AKJ88> Inside [ else if(c == ')') ] you've used [ st.pop() ], what if stack is empty?
AKJ88> Inside [ else if(c == ')') ] you've used [ st.pop() ], what if stack is empty?
Check input and AC output for thousands of problems on uDebug!
Re: 727 - Equation (Runtime Error)
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::

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;
}
Code: Select all
enjoying life .....
Re: 727 - Equation (Runtime Error)
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.
Input
Code: Select all
2
2
+
3
*
5
(
(
9
)
)
)
Code: Select all
235*+
9
Re: 727 - Equation (Runtime Error)
@lbv Again thanks for reply
Lastly I got AC
Lastly I got AC

Code: Select all
enjoying life .....
-
- New poster
- Posts: 5
- Joined: Thu Jul 19, 2012 1:02 am
Re: 727 - Equation (Runtime Error)
I keep getting WA, although I passed all test cases written here.
Can anyone write more test cases please.
Can anyone write more test cases please.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 727 - Equation (Runtime Error)
You can generate your own at:http://www.uvatoolkit.com/problemssolve.php
Check input and AC output for thousands of problems on uDebug!
Re: 727 - Equation
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
Last edited by abcman13 on Sat Jul 20, 2013 1:18 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 727 - Equation
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.
You can also try http://ideone.com/iZ7L1q
Try changing your input parsing. Maybe check if gets() returns NULL.
Check input and AC output for thousands of problems on uDebug!
Re: 727 - Equation
thanks for the help. my code was accepted.
education(runtime error)
Problem no:727
I got RE error but I can not what the problem is in my code.Please help me.
I got RE error but I can not what the problem is in my code.Please help me.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: education(runtime error)
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.
Check input and AC output for thousands of problems on uDebug!
727,uva problem
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 .
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 .