Please read the new rule regarding the restriction on the use of AI tools. ×

imrmnabil's blog

By imrmnabil, history, 8 months ago, In English

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.

Full text and comments »

  • Vote: I like it
  • +6
  • Vote: I do not like it