Problem:1922A
The code with char array:
#include <iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
int flag = 0;
cin>>n;
char a[n];
char b[n];
char c[n];
cin>>a;
cin>>b;
cin>>c;
for (int i = 0; i < n; ++i) {
if(a[i] != c[i] && b[i] != c[i]) {
flag = 1;
break;
}
}
if(flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
Error: wrong answer expected NO, found YES [503rd token]
The code with string:
#include <iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
int flag = 0;
cin>>n;
string a;
string b;
string c;
cin>>a;
cin>>b;
cin>>c;
for (int i = 0; i < n; ++i) {
if(a[i] != c[i] && b[i] != c[i]) {
flag = 1;
break;
}
}
if(flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
Result: Accepted
The compiler I selected was C++17 for both of the code.
I thought you should input char array as follows : char a[n]; for(int i=0;i<n;i++)cin>>a[i]; but now found new way to input char arrays :) Thanks XD
I have found the problem. I should have use a[n+1], b[n+1], c[n+1]. Using 'cin' is not the problem here in my case. Thank you.
The ostream operator is not defined for the char array by default, you are free to define yours if you want...
char[]
array is null-terminated, meaning that it must have place for\0
character. If you have $$$n$$$ letters, array length must be at least $$$n + 1$$$ then.Thank you very much. This was a silly and serious mistake.