1. 程式人生 > >讀入優化 && 輸出優化

讀入優化 && 輸出優化

找到 getch oid 優化 include write tex utc getc

qwq算是一個板子隨筆吧

快讀我在某大佬的博客中找到了更短的代碼

但是這個寫習慣了就改不了了qwq

其實是我不想改

廢話好多

直接貼代碼

 1 //讀入優化 
 2 inline int read(){
 3     char ch, c;
 4     int res;
 5     while (ch = getchar(), ch < 0 || ch > 9) c = ch;
 6     res = ch - 48;
 7     while (ch = getchar(), ch >= 0 && ch <= 9)
 8     res = (res << 3
) + (res << 1) + ch - 48; 9 if (c == -) res = -res; 10 return res; 11 } 12 //輸出優化 13 void write(int x){ 14 if (x < 0) putchar(-), x = -x; 15 if (x > 9) write(x / 10); 16 putchar(x % 10 + 0); 17 return; 18 }

然後在使用的時候

1 int main(){
2     int n;
3     n = read();
4
write(n); 5 }

註意別忘了頭文件名

#include <cstdio>

不許說我大括號不換行差評

讀入優化 && 輸出優化