#16816: c++ 求救


duncan103015 (錦毛爺)

School : 國立溪湖高級中學
ID : 85458
IP address : [140.128.101.9]
Last Login :
2019-06-30 13:35:43
b304. 00673 - Parentheses Balance -- UVa673 | From: [115.82.76.253] | Post Date : 2019-02-10 01:02

#include<iostream>
using namespace std;
int main()
{
int a,c,d,i;
string b;
while(cin>>d)
{ cin.ignore();
while(d--)
{ i=0;
getline(cin,b);

a=c=0;
while(b[i])
{
if (b[i]=='(')
a++;
if (b[i]==')')
a--;
if (b[i]=='[')
c++;
if (b[i]==']')
c--;

if((a<0)||(c<0))break;
i++;
}
if((a==0)&&(c==0))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
return 0;
}

 
#16837: Re:c++ 求救


duncan103015 (錦毛爺)

School : 國立溪湖高級中學
ID : 85458
IP address : [140.128.101.9]
Last Login :
2019-06-30 13:35:43
b304. 00673 - Parentheses Balance -- UVa673 | From: [115.82.76.253] | Post Date : 2019-02-11 22:50

#include
using namespace std;
int main()
{
int a,c,d,i;
string b;
while(cin>>d)
{ cin.ignore();
while(d--)
{ i=0;
getline(cin,b);

a=c=0;
while(b[i])
{
if (b[i]=='(')
a++;
if (b[i]==')')
a--;
if (b[i]=='[')
c++;
if (b[i]==']')
c--;

if((a<0)||(c<0))break;
i++;
}
if((a==0)&&(c==0))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
return 0;
}


 

100% WA (line:14)

 

 
#16843: Re:c++ 求救


duncan103015 (錦毛爺)

School : 國立溪湖高級中學
ID : 85458
IP address : [140.128.101.9]
Last Login :
2019-06-30 13:35:43
b304. 00673 - Parentheses Balance -- UVa673 | From: [115.82.76.253] | Post Date : 2019-02-12 22:36

#include
using namespace std;
int main()
{
int a,c,d,i;
string b;
while(cin>>d)
{ cin.ignore();
while(d--)
{ i=0;
getline(cin,b);

a=c=0;
while(b[i])
{
if (b[i]=='(')
a++;
if (b[i]==')')
a--;
if (b[i]=='[')
c++;
if (b[i]==']')
c--;

if((a<0)||(c<0))break;
i++;
}
if((a==0)&&(c==0))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
return 0;
}


 

100% WA (line:14)

 




程式漏洞:(([)])   :Yes  解答應為No

 
ZeroJudge Forum