문제

I am trying to solve one codechef practice problem subtraction game 1 with c programming and Code Blocks as IDE. I found one way of reading input faster than scanf() function but when I run my program I am getting error "undefined reference to 'getchar_unlocked' error". Can you guys tell me what I am doing wrong and is there any other method for reading input faster?

#include<stdio.h>
inline int fastread()
{
        int noRead=0;
        char p=getchar_unlocked();
        for(; p<33;) {
                p=getchar_unlocked();
        };
        while(p>32) {
                noRead = (noRead << 3) + (noRead << 1) + (p - '0');
                p=getchar_unlocked();
        }
        return noRead;
};
unsigned int gcd(unsigned int a, unsigned int b)
{
    if (b == 0)
       return a;
    else
       return gcd(b, a % b);
}
int main()
{
    int t,i,answer=0;
    unsigned int n;
    t = fastread();
    while(t--)
    {
        n = fastread();
        unsigned int a[n];
        for(i=0;i<n;i++)
            a[i]=fastread();
        answer = gcd(a[0],a[1]);
        for(i=2;i<n;i++)
            answer = gcd(a[i],answer);
        printf("%u\n",answer);
    }
    return 0;
}
도움이 되었습니까?

해결책

Quoting this answer on SO

getchar_unlocked is deprecated in Windows because it is thread unsafe version of getchar().

getchar_unlocked which has less overheads as compared to scanf or cin is not a standard feature of c or c++ , you can always use getchar() for that purposes here .

or you can write a function getchar_unlocked() to return the values of getchar() for on machine testing purposes if you are bound to use it in your online question .

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top