Re: 673 why RE???

Write here if you have problems with your C++ source code

Moderator: Board moderators

Re: 673 why RE???

Postby cse.mehedi » Sun Apr 01, 2012 3:05 am

Help me plz! :(
Code: Select all

#include<stdio.h>
#include<iostream>
#include<string.h>
int form(char s[10])
{
    int formt=0,n=1;
    for(int i=strlen(s)-1;i>=0;i--)
    {
        formt=formt+(s[i]-48)*n;
        n*=10;
    }
    return formt;
}

int main(void)
{

    using namespace std;
    char str[100],n[10];
    int m;
    gets(n);
    m=form(n);
    for(int p=0;p<m;p++)
    {
        gets(str);
        int num1=0,num2=0;
        for(int i=0;i<strlen(str);i++)
        {
        if(str[i]=='('||str[i]=='[')
        num1++;
        else if(str[i]==')'||str[i]==']')
        num2++;
        }
        if(num1==num2 && num1!=0 && num2!=0)
        printf("Yes\n");
        else printf("No\n");
    }
}

cse.mehedi
New poster
 
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

Re: 673 why RE???

Postby brianfry713 » Mon Apr 02, 2012 9:09 pm

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.
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Why WA !!!!!!!

Postby mahade hasan » Fri May 25, 2012 9:37 am

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;
}
Last edited by mahade hasan on Tue Jun 05, 2012 7:35 pm, edited 1 time in total.
we r surrounded by happiness
need eyes to feel it!
User avatar
mahade hasan
Learning poster
 
Posts: 62
Joined: Thu Dec 15, 2011 3:08 pm

Re: 673 why RE???

Postby brianfry713 » Fri Jun 01, 2012 1:56 am

Don't use getchar() and assume that it will read a newline. That won't work if there are trailing spaces.
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to C++

Who is online

Users browsing this forum: No registered users and 0 guests

cron