Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C语言中快速输入long和long?_C_Input_Long Integer_Long Long_Large Data - Fatal编程技术网

在C语言中快速输入long和long?

在C语言中快速输入long和long?,c,input,long-integer,long-long,large-data,C,Input,Long Integer,Long Long,Large Data,所以我已经使用这个函数来解决codechef问题有相当长的一段时间了,现在它是一种整数的快速输入方法 我的问题是这实际上是如何工作的,什么是fgetc_unlocked(stdin)(即使它被评论过),最重要的是,我如何优化它以使其长期运行 代码如下: inline void Scan_f(int a) { char c = 0; while(c<33)//shouldn't value of c to compare be less than 9 as digit vary betwee

所以我已经使用这个函数来解决codechef问题有相当长的一段时间了,现在它是一种整数的快速输入方法

我的问题是这实际上是如何工作的,什么是fgetc_unlocked(stdin)(即使它被评论过),最重要的是,我如何优化它以使其长期运行

代码如下:

inline void Scan_f(int a)
{
char c = 0;
while(c<33)//shouldn't value of c to compare be less than 9 as digit vary between 0 to 9?? 
//c = fgetc_unlocked(stdin);
c = getc(stdin);
a = 0;
while(c>33)
{
a = a*10 + c - '0';
//c = fgetc_unlocked(stdin);
c = getc(stdin);
}
inline void Scan\u f(int a)
{
字符c=0;

而(c在我看来,代码应该是:

inline unsigned long long Scan_f()
{
    int c;
    do
        c = fgetc(stdin);
    while ( (c < '0' || c > '9') && c != EOF );

    unsigned long long a = 0;
    while ( c >= '0' && c <= '9' )
    {
        a = a*10 + (c - '0');
        c = fgetc(stdin);
    }
    return a;
}
inline unsigned long long Scan\u f()
{
INTC;
做
c=fgetc(标准偏差);
而((c<'0'| c>'9')&&c!=EOF);
无符号长a=0;

while(c>='0'&&c为什么
c>33
vs.可能
while(c>'')
?为什么
char c=0
int c=0
@chux比较感谢..这就解释了其中一个问题。我在代码中编辑了注释,以便对一般读者更有意义。还有什么问题呢?
fgetc\u unlocked
getc
的线程不安全版本吗?如果你的程序在这一天保证是单线程的y提供了一些性能优势。@AndrewMedico“1”是0x31,实际上.33(十进制)是“!”,而这
while()
基本上跳过了领先的ASCII控件和
'
字符。整个过程甚至没有尝试验证输入字符是否在
0..9
范围内,只是盲目地假设这一点。哎呀,失败了。这就是我不花几秒钟来仔细检查ASCII表的原因。