發表文章

加速輸入輸出

圖片
        我們寫程式如果用一般的輸入輸出,常常會遇到一個問題,就是TLE,所以要加速。         最一般的就是這個 :                 std::cin.tie(0), std::cout.tie(0), std:: ios::sync_with_stdio(0);         這是將<iostream>跟<stdio.h>這個標頭檔解綁,使其達到加速的效果。         和這個 :                 int main(int argv, char** argc) + return 0;         這只有稍微加速而已。         還有這個 : scanf("%...", &x), printf("%...", x);         這個是直接使用c的函數達到加速的效果,不過當你使用<iostream>加上這個的時候 std::cin.tie(0), std::cout.tie(0), ios::std::sync_with_stdio(0);          scanf("%...", &x), printf("%...", x); 就不能用了,因為解綁了。         再來就是可以加速又可以減記憶體的方法,因為只有這三個有些題目過不了。 getchar, putchar----->unlocked         這個可以加速非常多,通常只要用這個,大部分的題目都可以過。 fre...

基礎題庫答案 zerojudge

a001   Python :     import sys     for s in sys.stdin:           print("hello, "+s)   c++ :     #include <iostream>     using namespace std;     int main() {         string a;         while (cin >> a) {             cout << "hello, " << a << endl;         }     }   c :     #include <stdio.h>     int main() {         char word[100];         while (scanf("%s", word)!=EOF) {             printf("hello, %s\n", word);         }     }   Java :     import java.util.Scanner;     public class JAVA {         public static void main(String[] args) {         ...