SNCOUP - Editorial

//ANYHELP why this code is not accepted?
#include
#include
#include
#include
#include

using namespace std;
 
    int main(){
 
int t;
cin>>t;
for(int r=0;r<t;r++){
           int q;
          cin>>q;
      char s[2][q];
    char d;
for(int i=0;i<2;i++){
for(int j=0;j<q;j++)
 cin>>s[i][j];
 }  
 int c=0;
    for(int i=0;i<2;i++){
for(int j=0;j<q;j++)
 if(s[i][j]=='*')c++;
 }    
 
    int count=0;
  int s1=0;
 int s2=0;
 d='a';
for(int k=0;k<q;k++){
if(s[0][k]=='*' || s[1][k]=='*') count++;
  if(s[0][k]=='*') s2=1;
if(s[1][k]=='*') s1=1;
if(s[0][k]=='*' && s[1][k]=='*') d='c';
}
int hor=s1+s2;
 
if(d=='c'){
if(count-1 == 1 && hor==2 && c>2){cout<<2<<endl;  }
  if(count-1 == 0 && hor==2 && c==2){cout<<1<<endl;  }
  if(count-1 == 1 && hor==2 && c==2){cout<<1<<endl;  }
if(count-1 > 1 && hor==2 ){cout<<count+hor-2<<endl;  }
if(count-1 >= 1 && hor!=2 ){cout<<count-1<<endl;  }
if(count-1 ==0 && hor!=2 ){cout<<0<<endl;  }
if(count-1 ==0 && hor!=2 && c==2){cout<<1<<endl;  }
 
}
 
else if(d!=c){
  if(count>=1)cout<<count-1<<endl; 
  else cout<<0<<endl;}
 
 
}
return 0;
                                              
}

  1. Blockquote

link text
anyhelp on why this code not accepted will be highly appreciated!!

Can anyone please provide a test case where my code fails?

Solution link : AVh0zv - Online C++0x Compiler & Debugging Tool - Ideone.com
Thanks:)

whats wrong with my solution-

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while (t--)
    {
        int n,i;
        cin>>n;
        char a[2][n];
        for (i=0;i<n;i++)
        {
            cin>>a[0][i];
        }
        for (i=0;i<n;i++)
        {
            cin>>a[1][i];
        }
        string s="";
        for (i=0;i<n;i++)
        {
            if (a[0][i]=='*'&&a[1][i]=='*')
            {
                s+="h";
            }
            else if (a[0][i]=='*'&&a[1][i]=='.')
            {
                s+="u";
            }
            else if (a[0][i]=='.'&&a[1][i]=='*')
            {
                s+="d";
            }
            else if (a[0][i]=='.'&&a[1][i]=='.')
            {
                s+="n";
            }
        }
        int fences=0;
        int x=n-1;
        for (i=0;i<(n);i++)
        {
            if (s[i]=='h'||s[i]=='u'||s[i]=='d')
            {
                x=i;
                break;
            }
        }
        for (i=x+1;i<n;i++)
        {
            if (s[i]=='h'||s[i]=='u'||s[i]=='d')
            {
                fences++;
            }
        }
        int hexist=0;
        for (i=0;i<n;i++)
        {
            if (s[i]=='h')
            {
                hexist=1;
                break;
            }
        }
        if (hexist==1)
            fences++;
        cout<<fences<<endl;
    }
    return 0;
}

Somebody please correct me where i went wrong?
Here’s my logic:
case 1: if the snakes are in row 1 or 2 or both but not vertically adjacent then i gave solution as total no. of snakes -1.
case 2:if the snakes are in row 1 or 2 or both and least 2 snakes are vertically adjacent then i gave solution as 1 + total no. of snakes -1 - no. of vertically adjacent pairs.
case 3 : if there is 0 or 1 snake in total then i gave solution as 0.
https://www.codechef.com/viewsolution/13947900

Can anyone pls explain why is “i” decremented in the Case 1(inside the if condition of for loop)??

please Suggest in which test case following code fails

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		string arr[2];
		cin>>arr[0]>>arr[1];
		ll ver=0,hori=0;
		ll count=0;		
		for(ll i=0;i<n;i++)
		{	
			if(arr[0][i]==arr[1][i] && arr[0][i]=='*')
				hori=1;
			if(arr[0][i]=='*' || arr[1][i]=='*')
				count++;
 
		}
		ll val=1,up=0,low=0;
		for (int i = 0; i < n; ++i)
		{
			if(arr[0][i]=='*')
				up++;
			if (arr[1][i]=='*')
				low++;
			if(up>1)
			{
				up=1;low=0;val++;
			}
			if(low>1)
			{
				low=1;up=0;val++;
			}
		}
		ll k=min(count-1+hori,val);
		if(k>0)
			cout<<k<<"\n";
		else 
			cout << "0\n";
	}
 
}

#include

using namespace std;

int main()
{
    int testcases ;
    cin >> testcases ;
    for (int t = 0 ; t < testcases ; t++){
        int n ;
        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 up_snake = 0 ; // if there is snake up
        int down_snake = 0 ; // if there is snake down
        int fence = 0 ; // answer
        int start_up = 0  ; // first snake up
        int start_down = 0 ; // first snake down
        for (int i = 0 ; i < n ; i++){
            if (a[0][i] == '*'){
                up_snake = 1 ;
                start_up = i ;
                break ;
            }
        }
        for (int i = 0 ; i < n ; i++){
            if (a[1][i] == '*'){
                down_snake = 1 ;
                start_down = i ;
                break ;
            }
        }


        if (up_snake == 1 && down_snake == 1){
            fence++ ; // for between fence
        }
       // cout << "basic fence " << fence << endl ;
        int start_index = start_up ; // starting index
        int count_up = 1 ;
        int count_down = 0 ;

        if (start_up > start_down){
            count_down = 1 ;
            count_up = 0 ;
            start_index = start_down ;

        }
        if (start_up == start_down){
            count_up = 1 ;
            count_down = 1 ;
        }
        if (start_index == n-1){
            cout << 0 << endl ;
        }
        else {

            for (int i = start_index+1 ; i < n ; i++){
                if (a[0][i] == '*' && a[1][i] == '*'){
                    fence ++ ;
                    count_down = 1 ;
                    count_up = 1 ;
                }

                else if (a[0][i] == '*' && count_up == 1){
                    fence ++ ;
                    count_down = 0 ;

                }
                else if (a[0][i] == '*' && count_up == 0){
                    count_up ++ ;
                }
                else if (a[1][i] == '*' && count_down == 1){
                    fence ++ ;
                   // cout << " fence down at "  <<i << endl  ;
                   count_up = 0 ;

                }
                else if (a[1][i] == '*' && count_down == 0){
                    count_down ++ ;
                }

                }

                cout << fence << endl ;
            }

        }


    return 0;
}

can anyone tell me in what am i doing wrong ???

#include<stdio.h>
#include<string.h>
int main()
{
int t,n,i,first,second,a,b,count;
char arr[2][100004];
scanf("%d",&t);
while(t–)
{
first=0;
second=0;
count=0;
a=0;b=0;
scanf("%d",&n);
scanf("%s",&arr[0]);
scanf("%s",&arr[1]);
for(i=0;i<n;i++)
{
if(arr[0][i]==’’)
first++;
if(arr[1][i]==’
’)
second++;
}
if(first+second<2)
{
printf(“0\n”);
continue;
}
if(first==1&&second==1)
{
printf(“1\n”);
continue;
}
if(first==0)
{
printf("%d\n",second-1);
continue;
}
if(second==0)
{
printf("%d\n",first-1);
continue;
}
for(i=0;i<n;i++)
{
if(arr[0][i]==’’)
a++;
if(arr[1][i]==’
’)
b++;
if(a==2)
{
count++;
a–;
if(b>0)
b–;
}
if(b==2)
{
count++;
b–;
if(a>0)
a–;
}
}
printf("%d\n",count+1);
}
}

this is my code
please tell where it is failing

what’s wrong with my code.

https://www.codechef.com/viewsolution/13931788

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 ???CodeChef: Practical coding for everyone

Can anyone please tell me why I’m getting WA, here is the link to my code CodeChef: Practical coding for everyone

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

please someone tell whats wrong with this program
https://www.codechef.com/viewsolution/13944522

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);
	}
}

}

Please tell where the input fails CodeChef: Practical coding for everyone

can any one help me in this. i am not getting what is wrong…
My_code

This is absolute solution and it help me a lot thanks .
programming assignment help

plz tell me test case for which my program produces wrong output thanks _/\ _

link text

@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