Re: 727 Equation TLE
Posted: Wed Feb 06, 2013 7:05 pm
thanks man, line 63 got problem, somehow '(' was getting poped up because of perced check.fixed it got AC.
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;
}
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 .....
Code: Select all
2
3
1
+
2
Code: Select all
3
12+
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;
}
shuvokr wrote: Again and again RE ...
Please help
Code: Select all
2
2
+
3
*
5
(
(
9
)
)
)
Code: Select all
235*+
9
Code: Select all
accepted