vendredi 6 août 2021

fastscan method behaving weirdly

I today came to know about fastscan() method in c++. I used it today but it's behaving unexpectedly. Its probably taking wrong input or messing up with std::cin. When I use it on VS Code then correct output is being shown 3,5,0 but when i submit the solution(on codeforces then wrong output -2,-2,-2 is being shown). I can't understand what's going wrong. CF handle: Joaquin144 Submission ID: 125085949

    void fastscan(int &x)
{
    bool neg = false;
    register int c;
    x = 0;
    c = getchar();
    if (c == '-')
    {
        neg = true;
        c = getchar();
    }
    for (; (c > 47 && c < 58); c = getchar())
        x = 48 + (x << 1) + (x << 3) - c;
    if (!neg)
        x *= -1;
}

//in main function I have also used cin for string input

string s;cin>>s;

Correct output is highlighted

Aucun commentaire:

Enregistrer un commentaire