有时候我们需要输入大量的数据,如果使用cin或者scanf会因为效率较低导致程序运行超时,这时候就需要使用读入优化了。完善下面的程序,使得程序能快速读入数字。
#include<bits/stdc++.h> using namespace std; int a[1000007]; void read(int &x) { int f=1; x=0; char s=getchar(); while(____(1)______) { if(s=='-') _____(2)_____ s=getchar(); } while(s>='0'&&s<='9') { ____(3)____ s=getchar(); } _____(4)_____ } int main() { int ans=0; int n; read(n); for(int i=0;i<n;i++) { ____(5)______ ans+=a[i]; } printf("%d\n",ans); }