简体   繁体   中英

Getting error outputs due to using ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); in the code

In this code below the ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); statement seems to be causing some problems. I tried with different variation like ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); or ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

For these test cases:

5

5

apple

15

schtschurowskia

6

polish

5

tryst

3

cry

The expected output should be:

YES

NO

YES

NO

YES

But due to this line ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); I'm getting

NO

YES

YES

YES

YES

Note that: these results I'm getting from online judges but in reality I'm getting the output as expected but all at once after finishing all my test cases , which was unexpected. So my question is why this delay is happening and how come the online judges are giving a wrong output.

#include "bits/stdc++.h"
using namespace std;

int main() {
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin >> t;
while(t-- > 0){
    int n, cnt = 0, rem = 0;
    cin >> n;
    char str[n];
    scanf("%s", str);
    for (int i = 0; i < n; i++){
        if (str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' && str[i] != 'u'){
        cnt++;
        rem = max(cnt, rem);
    }
    else
        cnt = 0;
    }
    cout << (rem < 4 ? "YES" : "NO") << '\n';
}
    return 0;
}

You're explicitly unsyncing the standard C++ streams and the standard C streams, but then mixing them in your code. Switch the scanf with cin .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM