Are these test cases correct ?
$ ./test < test.txt
6
4
0
0
2
6
4
$ cat test.txt
7
<><><><<<<>>>>
<<>>
><
><>
<><
<<>><<<<>>>>
><<>><<<>>>
Are these test cases correct ?
$ ./test < test.txt
6
4
0
0
2
6
4
$ cat test.txt
7
<><><><<<<>>>>
<<>>
><
><>
<><
<<>><<<<>>>>
><<>><<<>>>
def check(s):
t=0,ans=0
for i=0 to N-1:
if s[i]==β<β: t++;
else:
tβ;
//Now, if t=0, means, the string s[0,i] is valid.
if t==0: ans=max(ans,i+1) ------> I can see there is no use of max function here as i always more than max every time t==0, so simple ans=i+1 is sufficient.
else if t<0: break //string s whole is invalid.
print ans
#include
#include<bits/stdc++.h>
#include
using namespace std;
typedef unsigned long long int ull;
#define F first
#define S second
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
#define fastscan ios_base::sync_with_stdio(0); cin.tie(NULL);
int main(int argc, char const *argv[])
{
long int t;
cin>>t;
while(t--){
string s;
cin>>s;
ull len=s.length();
stack<char> st;
ull run=0;
for (ull i = 0; i < len; ++i)
{
if(s[i]=='<'){
st.push('<');
run++;
}
else if(s[i]=='>' && !st.empty()){
st.pop();
run++;
}
else{
break;
}
}
cout<<run<<endl;
}
return 0;
}
//Anybody tell me whats wrong in this codeβ¦
I have implemented this algorithm in Go and tried to run it but getting a time limit exceed error. But the same algorithm Iβve implimented in Python3 and run it and it accepted. Is Go compiler not well implemented?
Could anyone please tell me what I am missing in my code? Getting WA. Have attached my own test cases.
Can anyone tell me what is wrong with this solution? O4w7qo - Online C++0x Compiler & Debugging Tool - Ideone.com
Can anyone help me with this
[1]. Any suggestion is warmly welcomed,thankyou
[1]: https://www.codechef.com/viewsolution/18731588
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ll t;
cin>>t;
while(tβ)
{
//ll cnt=0;
stack s;
string s1;
cin>>s1;
ll n=s1.size();
if(n==1||s1[0]==β>β)
{
cout<<0<<endl;
continue;
}
int i=0;
ll cnt=0,res=0;
while(s1[i]!=β\0β)
{
if(s1[i]==β<β)
{
s.push(s1[i]);
cnt++;
}
else if(s1[i]==β>β)
{
s.pop();
}
if(s.empty())
{
res+=cnt;
cnt=0;
}
i++;
}
cout<<res*2<<endl;
}
return 0;
}
Rest is your implementation of code you can check my code
link text
both author and setter has wrong ans.
Check for β>><>β this.
answer should be 2.
but your solution shows, 0.
Can anybody tell me where the mistake is in this code. Iβm getting WA
Try this case:
1
<<><>>
Output should be 6
Thanks got it!!!
You assume, that max input length is 100, why?
See the second test case - Xxe1sf - Online C++ Compiler & Debugging Tool - Ideone.com (answer is not 4 for sure)
Can you help me where i m getting wrong
thank you so much
for input
1
<<>
your code returns 2, but correct is 0
Thanks a lot!
Hadnβt understood the question clearlyβ¦