大模板!!!

        NOIP大模板(第一版)

一.文件输入,输出

 1 #include<cstdio>
 2 using namespace std;
 3 int main(void)
 4 {
 5     freopen("","r",stdin);
 6     freopen("","w",stdout);
 7     //...
 8     fclose(stdin);
 9     fclose(stdout);
10     return 0;
11 }

二.输入,输出优化!!!(快读&快输)  

  (1)快读

    1.整数读取 (需要调用 <iostream>  <cstdio>

1 inline int read()
2 {
3     int x=0,w=0;
4     char ch=0;
5     while(!isdigit(ch)) w|=ch=='-',ch=getchar();
6     while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
7     return w?-x:x;
8 }

    2.浮点数读取(需要调用 <iostream>  <cstdio>

 1 inline double  read()
 2 {
 3     int w=0,y=0;
 4     double x=0,t=0.1;
 5     char ch=0;
 6     while(!isdigit(ch)) w|=ch=='-',ch=getchar();
 7     while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
 8     y|=ch=='.';
 9     if(y)
10     {
11         ch=getchar();
12         while(isdigit(ch)) x+=(ch^48)*t,t*=0.1,ch=getchar();
13     }
14     return w?-x:x;
15 }

  (2)快输

   1.整数输出(需要调用 <iostream>  <cstdio>

 1 inline void write(int x)
 2 {
 3     if(x<0)
 4     {
 5         putchar('-');
 6         x=-x;
 7     }
 8     if(x>9) write(x/10);
 9     putchar(x%10+'0');
10 }

  2.浮点数输出(暂无)

 

猜你喜欢

转载自www.cnblogs.com/Blacktears/p/9931620.html