Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Why Codeforces not accepted my code where i used char array?? But accept the same code with string??

Правка en1, от imrmnabil, 2024-01-19 20:20:44

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.

Теги problem, help, whats going on, 1922a

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский imrmnabil 2024-01-19 20:20:44 1351 Initial revision (published)