讀入數據在編程中是永遠離不開的,如何快速有效地讀入數據是亟待解決的問題。有的時候幾ms的時間就是Accepeted和Time Limit Exceeded的雲泥之別,讀入優化則可以在此發揮它的最大作用。c++代碼如下:
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<string>
#include<iomanip>
using namespace std;
int readint()
{
int i=0,f=1;
char s;
for(s=getchar();(s<'0'||s>'9')&&s!='-';s=getchar());
if(s=='-')
{
f=-1;
s=getchar();
}
for(;s>='0'&&s<='9';s=getchar())
i=(i<<3)+(i<<1)+s-'0';
return i*f;
}
int main()
{
int a,b,sum;
a=readint();
b=readint();
sum=a+b;
cout<<sum;
return 0;
}
(以“A+B Problem”爲例)
這樣,可以有效縮短輸入時間,增加通過的可能性。
(P.S. 如果用暴力堪堪可以過的題可以嘗試使用)
——我認爲return 0,是一個時代的終結。