jeudi 24 décembre 2020

How to resolve this issue ? showing keith error

I was writing a simple c++ program

#include <bits/stdc++.h>
#define ll long long
#define ul unsigned long long
#define ld long double
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repi(i, a, b) for (int i = (a); i > (b); i--)
#define all(x) x.begin(), x.end()
#define ks(x) (cout << #x << ":" << (x) << '\n')
#define fastio ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define gcd _gcd
using namespace std;
const ll mod = 1000000007;

int main()
{
    fastio;
    ll tc = 1;
    cin >> tc;
    for (ll t = 0; t < tc; t++)
    {
        ll n;
        cin >> n;
        string s;
        cin >> s;
        ll cnt = 0;
        ll i = n - 1;
        if (s[n - 1] == ')')
        {
            i--;
            cnt++;
            while (s[i] == ')' && i > -1)
            {
                i--;
                cnt++;
            }
        }
        if (cnt > n / 2)
            cout << "YES\n";
        else
        {
            cout << "NO\n";
        }
    }
    return 0;
}

and input it with *

5
2
))
12
gl))hf))))))
9
gege)))))
14
)aa))b))))))))
1
)*

but it is showing output i am unable to understand please help

/home/keith/builds/mingw/gcc-9.2.0-mingw32-cross-native/mingw32/libstdc++-v3/include/bits/basic_string.h:1067: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]: Assertion '__pos <= size()' failed.

Aucun commentaire:

Enregistrer un commentaire