You missed corner case when length < 3, for example for
1
1
your code returns ‘Good’…
You missed corner case when length < 3, for example for
1
1
your code returns ‘Good’…
feeling bad to have missed this case thanks
don’t be sad, I can write a book about stupid bugs I did in contests
My advice here is, do not use some side effects (like if I scanned whole string), use additional boolean
flag that is set to false
at the beginning and when you really find what you are looking for, set it to true
.
Also you do not need to use such difficult input reading, see my code (CodeChef: Practical coding for everyone ) for this problem if you want or this one (CodeChef: Practical coding for everyone ), to see how to use StringTokenizer.
what is wrong with this…
#include <stdio.h>
#include <string.h>
int main(void)
{
int t;
char a , b , c ,d ,count ;
scanf("%d" , &t);
while(t–)
{
count = 0;
a = getchar();
b = getchar();
c = getchar();
while( (d = getchar()) != ‘\n’)
( (a==‘0’ && b==‘1’ && c==‘0’) || (a == ‘1’ && b==‘0’ && c==‘1’)) ? ( (count++) , (a = b) , ( b = c) , (c = d )): ((a = b) , ( b = c), (c = d ));
(count > 0)?(printf(“Good\n”)):(printf(“Bad\n”));
}
return 0;
}
Try pasting ur code after pressing CTRL+K
use ‘or’ instead of ‘and’, its mentioned in the description of the question.
thanks man
C++ Stl Advantage not shorted as python but yeah little bit short code
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
string s1;
cin>>s1;
int val1=s1.find("010");
int val2=s1.find("101");
if(val1>=0||val2>=0){
cout<<"Good"<<endl;
}else{
cout<<"Bad"<<endl; }
}
return 0;
}
Hey guys,
I didn’t want to do the direct checking the string method for each case so I added a bit of math there but I am getting wrong answer after submitting. I have tried every test case but maybe I am missing out something. Can you please help me out?
Here’s the code
int main(void) {
// your code goes here
int t;
scanf("%d", &t);
while(t–)
{
int length,ans = 0;
char s[100001];
scanf("%s", s);
length = strlen(s);
for(int i =0; i<length - 2;i = i + 2)
{
int x = (s[i] - '0');
x++;
x = x % 2;
if(x == (s[i + 1] - '0'))
{
x++;
x = x % 2;
if(x == (s[i + 2] - '0')){
ans = 1;
break;
}
}
}
if(ans == 1)
printf("Good\n");
else
printf("Bad\n");
}
return 0;
}
Oh! I found that I should be using i++ instead of i = i + 2.