Your Code is not working for
Input:
.**
**.
Your code’s Output: 2
Expected Output :3
Anyone, please?
What is wrong with my this code, it is working fine for all tests which i could think. Please can someone tell where it is failing ???https://www.codechef.com/viewsolution/13961222
Can anyone please tell me why I’m getting WA, here is the link to my code https://www.codechef.com/viewsolution/13962362
Can someone please tell what is wrong with my code.
If possible give the test case where it fails. Here is the link to my code:
https://www.codechef.com/viewsolution/13934000
thanks @vijju123 , I got the failure but late . I was tried more then 50 inputs but was not finding the failure .So i was very exited if someone reply as early as possible.
Failure:
.**
**.
what is wrong with my code i couldn’t understand why i got a wrong answer…
import java.util.*;
class snckdwn {
public static void main(String[] args) {
Scanner ob = new Scanner(System.in);
int t = ob.nextInt();
while(t-- > 0)
{
int n = ob.nextInt();
char a[][] = new char[2][n];
for(int i=0;i<2;i++)
{
String s = ob.next();
for(int j=0;j<n;j++)
{
a[i][j] = s.charAt(j);
}
}
boolean upper = false;
boolean lower = false;
boolean hl = false;
boolean left = false;
boolean leftdiag = false;
boolean rightdiag = false;
int count = 0;
for(int i=0;i<n;i++)
{
char te, te1, be, be1;
te = a[0][i];
be = a[1][i];
if(hl==false)
{
if(te=='*')
upper = true;
if(be=='*')
lower = true;
}
if(upper==true&&lower==true)
{
upper = lower = false;
hl = true;
count++;
}
if(te=='*'&&be=='.')
{
if(rightdiag==true)
{
rightdiag = false;
continue;
}
if(leftdiag==true)
{
count++;
continue;
}
leftdiag = true;
if(left==true)
{
count++;
continue;
}
left = true;
}
else if(te=='.'&&be=='*')
{
if(leftdiag==true)
{
leftdiag = false;
continue;
}
if(rightdiag==true)
{
count++;
continue;
}
rightdiag = true;
if(left==true)
{
count++;
continue;
}
left = true;
}
else if(te=='*'&&be=='*')
{
if(left==false)
left = true;
else
{
count++;
left = false;
}
}
else
continue;
}
System.out.println(count);
}
}
}
Check here. if that doesnt help, comment further.
@code_man Ur code gives wrong output for following test cases:
4
7
*.....*
.*****.
7
.*****.
*.....*
11
...*...*...
....***....
11
....***....
...*...*...
The correct output is :
5
5
3
3
but your code gives output :
6
6
4
4
plz edit ur code and format it nicely
Could anyone help me in figuring out the test cases where my solution is failing? i tried hard but could get any.!!
Link to solution is https://www.codechef.com/viewsolution/14017280 .
can’t find what’s wrong in this code
#include
using namespace std;
int main(){
int t,n;
cin>>t;
while(t--){
cin>>n;
char a[2][n];
for(int i=0;i<2;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
int fences = 0;
char prev1='.', prev2='.', row1=false, row2=false;
for(int i=0;i<n;i++) {
if(a[0][i]=='*'){
row1=true;
}
if(a[1][i]=='*'){
row2=true;
}
if((row2==row1)and(row1==true)){
fences++;
break;
}
}
for(int i=0;i<n;i++){
if(((a[0][i]=='*')and(a[1][i]=='*'))and((prev1=='*')or(prev2=='*'))) {
fences++;
if(prev1=='*')
prev2='*';
else if(prev2=='*')
prev1='*';
continue;
}
if((a[0][i]=='*') and (prev1!='*')){
prev1='*';
}
else if((a[0][i]=='*') and (prev1=='*')) {
fences++;
prev2='.';
}
if((a[1][i]=='*') and (prev2!='*')){
prev2='*';
}
else if((a[1][i]=='*') and (prev2=='*')){
fences++;
prev1='.';
}
}
cout<<fences<<endl;
}
}