相关疑难解决方法(0)

getchar_unlocked()VS scanf()VS cin

这三种输入函数在编程语言中有什么区别.他们以不同的方式相互输入吗?

1.getchar_unlocked()

 #define getcx getchar_unlocked

 inline void inp( int &n ) 
 {
    n=0;
    int ch=getcx();int sign=1;
    while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();}

    while(  ch >= '0' && ch <= '9' )
            n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
    n=n*sign;
  }   
Run Code Online (Sandbox Code Playgroud)

2.scanf("%d",&n)

3.cin>>n

输入整数时哪一个花费的时间最少?

我在c ++中使用THese头文件,其中所有3个用c ++运行;

  #include<iostream>
  #include<vector>
  #include<set>
  #include<map>
  #include<queue>
  #include<stack>
  #include<string>
  #include<algorithm>
  #include<functional>
  #include<iomanip>
  #include<cstdio>
  #include<cmath>
  #include<cstring>
  #include<cstdlib>
  #include<cassert>
Run Code Online (Sandbox Code Playgroud)

c++ scanf

13
推荐指数
2
解决办法
2万
查看次数

使用putchar_unlocked进行快速输出

我想在我的代码中使用快速输入和输出.我理解使用getchar_unlocked以下功能进行快速输入.

inline int next_int() {
    int n = 0;
    char c = getchar_unlocked();
    while (!('0' <= c && c <= '9')) {
        c = getchar_unlocked();
    }
    while ('0' <= c && c <= '9') {
        n = n * 10 + c - '0';
        c = getchar_unlocked();
    }
    return n;
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释我如何使用putchar_unlocked()功能快速输出?

我正在经历这个问题,有人说putchar_unlocked()可以用来快速输出.

c++

7
推荐指数
1
解决办法
7621
查看次数

标签 统计

c++ ×2

scanf ×1