Else you can paste your code as a answer so that other users can also take a chance to find error case
whats wrong in This β¦ ?
for _ in range(int(input())):
n = int(input())
s1 = str(input())
s2 = str(input())
s3 = str()
d = 0
for i in range(n):
if s1[i] == '*' and s2[i] == '*':
d+=1
break
for j in range(n):
if s1[j] == '*' or s2[j] == '*':
s3+='*'
if d == 1 or len(s3) == 0:
print(len(s3))
else:
print(len(s3) - 1
thanxx man.
I used a different approach, was getting a wrong answer but couldnβt figure a test case for which this will fail. Consider the number of β's in row 1 as stars1, and the number of stars in row2 as stars2. Also, for columns where both row 1 and row 2 have a 'β, count them in a variable common. So the approach is that if(common>0), add a fence(the horizontal fence). And then the number of vertical fences that will be added will be= (stars1 + stars2- common -1) .
I cant figure out why will it fail.Can someone point out a test case. Here is the code:
thank you for trying! @sai_rathan
Can anyone provide a test case for which the code does not work?
I Dare you if you can tell where it will fail.
if(arr[0][i]=='*' && arr[1][i]=='.' && arr[0][i+1]=='.' && arr[1][i+1]=='*'){
ans--;
i++;
}
else if(arr[0][i]=='.' && arr[1][i]=='*' && arr[0][i+1]=='*' && arr[1][i+1]=='.'){
ans--;
i++;
}
I think in the if condition your trying to access a[0][i+1] but when you are accessing last element it will try to access its next element which is not present. I think this is causing some trouble for larger value of βnβ though Iβm not sure.
The test cases already found where you were wrong so no point in dare XD.
On a side note- Request nicely and people will help
Can any one help me out where I went wrong
https://www.codechef.com/viewsolution/13933535
I was really working from yesterday night and could not find where it is failing.So please and please help me out
#include<bits/stdc++.h>
#define S_ a[0][i]==ββ && a[1][i]==β.β
#define _S a[0][i]==β.β && a[1][i]==ββ
#define SS a[0][i]==ββ && a[1][i]==ββ
#define __ a[0][i]==β.β && a[1][i]==β.β
#define SNAKE a[0][i+1]==ββ||a[1][i+1]==ββ
using namespace std;
int main(){
inputSection
//-----------------------------------------------
int firstIndex = 0;
int lastIndex=0;
for(int i=0;i<n;i++)
{
if(a[0][i]==ββ || a[1][i]==ββ)
{
firstIndex = i;
break;
}
}
for(int i=n-1;i>=firstIndex;iβ)
{
if(a[0][i]==ββ || a[1][i]==ββ)
{
lastIndex = i;
break;
}
}
bool hz = false;
int vt =0;
if(firstIndex==lastIndex && a[0][firstIndex]==ββ&&a[1][lastIndex]==ββ)
{
hz=true;
}
else if(firstIndex==lastIndex)
{
hz = false;
vt=0;
}
for(int i = firstIndex;i<lastIndex;)
{
if(S_)
{
if(!SNAKE)
{i++;continue;}
i=i+1;
if(S_)
vt++;
else if(SS){hz=true;
vt++;}
else if(_S){
hz= true;
}
}
else if(_S){
if(!SNAKE)
{
i++;
continue;
}
i= i+1;
if(_S)
{
vt++;
}
else if(S_)
{
hz=true;
}
else if(SS){
hz= true;
vt++;
}
}
else if( SS){
if(!SNAKE)
{
i++;
continue;
}
i= i+1;
if(_S)
{
vt++;
hz=true;
}
else if(S_)
{
hz=true;
vt++;
}
else if(SS){
hz= true;
vt++;
}
else{
hz=true;
}
}
else // increment i
{i++;}
}
if(hz)
cout<<vt+1<<endl;
else
cout<<vt<<endl;
}
return 0;
}
**Can AnyOne help me in getting error in this code ** Here SOME Macros are used _β>Dot ans Sβ>Snake I m checking pair wise snake and next snake and then applying the opartion on vertical line and horizontal line i used a boolean for Hz line if it exists then add 1 to vertical linesβ¦
https://www.codechef.com/viewsolution/13933535
This is the link to mmy code.So please help me out where I went wrong
If anyone wantβs to check out a correct
[1]
It's quite simple
[1]: https://www.codechef.com/viewsolution/13932694
Anyone who can tell me a test case ? Here is my code. Getting WA for no reason.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,t;
char a[200010];
char b[200010];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf(" %s",a);
scanf(" %s",b);
int cnt=0;
int upper=0;
int lower=0;
for(int i=0;i<n;i++)
{
if(a[i]=='*')
upper++;
if(b[i]=='*')
lower++;
if(upper>=1 && lower>=1)
{
cnt=1;
break;
}
}
upper=lower=0;
for(int i=0;i<n;i++)
{
if(a[i]=='*' && b[i]=='*')
cnt++;
else if(a[i]=='*')
{
upper++;
cnt++;
}
else if(b[i]=='*')
{
lower++;
cnt++;
}
if(upper==1 && lower ==1)
{
cnt--;
lower=upper=0;
}
if(lower>1 || upper>1)
{
if(a[i]=='*' && b[i]=='.')
{
upper=1;
lower=0;
}
else if(b[i]=='*' && a[i]=='.')
{
lower=1;
upper=0;
}
else
upper=lower=0;
}
//printf("at %d count= %d\n",i,cnt);
}
if(cnt)
cnt--;
printf("%d\n",cnt);
}
return 0;
}
doing i-- in the last loop wonβt cause the loop to run infinitely? In c++ code given here?
//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;
}
- Blockquote
Can anyone please provide a test case where my code fails?
Solution link : https://ideone.com/AVh0zv
Thanks:)