0
我正在嘗試解決一個codechef練習問題subtraction game 1與c編程和代碼塊作爲IDE。我發現一種閱讀輸入比scanf()函數更快的方式,但是當我運行我的程序時,我收到錯誤「未定義引用'getchar_unlocked'錯誤」。你們能告訴我我做錯了什麼嗎?還有其他方法可以更快地讀取輸入嗎?對'getchar_unlocked'錯誤的未定義引用
#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;
}
我認爲'getchar_unlocked'在Windows中被棄用,因爲它是線程不安全的'getchar()'.Sp的版本,可能它在代碼塊庫中不可用。除非速度因素太多,否則請儘量避免getchar_unlocked。 –
可能有人應該問MS爲什麼他們不支持POSIX? – mfro
@Jayesh這意味着我不能使用getchar_unlocked。你能否提出其他更快的閱讀輸入方式? –