Page 12 of 17

Re: 673 why RE???

Posted: Mon Apr 02, 2012 9:09 pm
by brianfry713
Your program can assume that the maximum string length is 128.

A string of this type is said to be correct if it is the empty string.

Why WA !!!!!!!

Posted: Fri May 25, 2012 9:37 am
by mahade hasan
Edited but still WA!!!

Code: Select all

#include<stdio.h>

int main()
{
    int I,K,L,Flag,M,N,Test;
    char Stack[200],C;
    
    while(scanf("%d",&Test)==1)
    {
       //getchar();
       for(;Test>0;Test--)
       {
          I=-1;
          Flag=0;
          scanf("\n");
          while(scanf("%c",&C)&&C!='\n')
          {
             if(Flag==0)
             {
               if(C=='('||C=='[') Stack[++I]=C;
               else if(C==')')
               {
                  if(I<0) Flag=5;
                  else if(Stack[I]=='(') --I;
                  else Flag=5;
               }
               else if(C==']')
               {
                  if(I<0) Flag=5;
                  else if(Stack[I]=='[') --I;
                  else Flag=5;
               }
             }
          }
          if(Flag==0) printf("Yes\n");
          else printf("No\n");
       }
    }
    return 0;
}
[/color]

Re: 673 why RE???

Posted: Fri Jun 01, 2012 1:56 am
by brianfry713
Don't use getchar() and assume that it will read a newline. That won't work if there are trailing spaces.

Re: 673 - Parentheses Balance

Posted: Thu Jul 26, 2012 4:49 pm
by wonderful008
I have gotten WA for many times...
Can anyone help me?

#include <iostream>
using namespace std;
#define MAX 100
int Stack[MAX], top=-1;
int isEmpty();
int isFull();
int Push(char n);
char Pop();
char View();
int length(char data[]);

int main()
{
int N;
while (cin >> N) {
cin.ignore();
char data[MAX];
for (int i = 0; i < N; i++) {
cin.getline(data,MAX);
int len = length(data);
int correct = 1;
while (!isEmpty()) Pop();

for (int i = 0; i < len; i++) {
if (data == '(' || data == '[') {Push(data);}
else if (data == ')') {
if (isEmpty() || View() != '(') {correct = 0; break;}
Pop();
}
else if (data == ']') {
if (isEmpty() || View() != '[') {correct = 0; break;}
Pop();
}
}

if (!isEmpty()) correct = 0;
correct == 1? cout << "Yes\n":cout << "No\n";
}
}
return 0;
}


int isEmpty()
{
if (top < 0) return 1;
else return 0;
}

int isFull()
{
if (top >= MAX-1) return 1;
else return 0;
}

int Push(char n)
{
if (isFull()) return -1;
Stack[++top] = n;
return 0;
}

char Pop()
{
if (isEmpty()) return -1;
return Stack[top--];
}

char View()
{
if (isEmpty()) return -1;
return Stack[top];
}

int length(char data[])
{
int x = 0;
for (int i = 0; data!='\0'; i++)
x++;
return x;
}

Re: 673 - Parentheses Balance

Posted: Fri Jul 27, 2012 1:30 am
by brianfry713
Input:

Code: Select all

1
()
1
()
Output should be:

Code: Select all

Yes

673 Parentheses Balance - WA ?

Posted: Mon Aug 13, 2012 8:40 am
by c0debreak
I don't know why, got lots of test cases passed:

Code: Select all

Remove after AC

Re: 673 Parentheses Balance - WA ?

Posted: Mon Aug 13, 2012 11:21 pm
by brianfry713
check your code with an empty string for an input, you need to read the input line by line.

Re: 673 Parentheses Balance - WA ?

Posted: Tue Aug 14, 2012 1:18 pm
by c0debreak
I think if the whole line is empty, cin will not write to the string, am I wrong ?

Re: 673 Parentheses Balance - WA ?

Posted: Tue Aug 14, 2012 11:07 pm
by brianfry713
Yes that could be your problem. Try using getline(cin,str);

Re: 673 Parentheses Balance - WA ?

Posted: Wed Aug 15, 2012 11:06 am
by c0debreak
If i switch to getline and check for empty strings;

Code: Select all

		getline (cin, str);
		if (str.empty()) { ++N; continue; }
I got a TLE, guess it's waiting for input maybe

Re: 673 Parentheses Balance - WA ?

Posted: Wed Aug 15, 2012 10:59 pm
by brianfry713
Print Yes on an empty string and count it as a line. Next time post your complete updated code.

Re: 673 Parentheses Balance - WA ?

Posted: Fri Aug 17, 2012 4:33 am
by c0debreak
Thanks, I've updated code to handle empty string now, but still WA

Re: 673 Parentheses Balance - WA ?

Posted: Sat Aug 18, 2012 1:36 am
by brianfry713
Try input:
((

Re: 673 Parentheses Balance - WA ?

Posted: Sun Aug 19, 2012 6:27 am
by c0debreak
Got ACC, thanks

673 WA!!

Posted: Fri Aug 31, 2012 8:28 pm
by sornaCse
I am so tired for this problem!
Please any one tell me where is my error.
I tried many test case but WA!! :oops: :(