I got stuck in solving this problem.My approach is to create an array of strings where each one of the 'n' lines of input are strings ,I have tried a lot but still not able to figure out why count which is the answer always coming 0?
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
cin>>n;cin.ignore();
string s[n];
int count=0;
for(int i=0;i<n;i++)
{
getline(cin,s[i]);
}
for(int i=0;i<n;i++)
{
int t=0;
for(int j=0;j<n;j++)
{
if(s[j][0]==s[i][0]-'1'&&s[j][2]==s[i][2]||s[j][0]==s[i][0]+'1'&&s[j][2]==s[i][2]||s[j][0]==s[i][0]&&s[j][2]==s[i][2]+'1'||s[j][0]==s[i][0]&&s[j][2]==s[i][2]-'1')
{
t++;
}
}
if(t==4)
{
count++;
}
}
cout<<count;
}
Aucun commentaire:
Enregistrer un commentaire