zoukankan      html  css  js  c++  java
  • 终极快速读入挂极其使用方法

    当遇到输入很多的时候可以使用(据说1e5以上),能减少相当多的时间

    模板

    #define FI(n) FastIO::read(n)
    namespace FastIO {
    	const int SIZE = 1 << 16;
    	char buf[SIZE], obuf[SIZE], str[60];
    	int bi = SIZE, bn = SIZE, opt;
    	int read(char *s) {
    		while (bn) {
    			for (; bi < bn && buf[bi] <= ' '; bi++);
    			if (bi < bn) break;
    			bn = fread(buf, 1, SIZE, stdin);
    			bi = 0;
    		}
    		int sn = 0;
    		while (bn) {
    			for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
    			if (bi < bn) break;
    			bn = fread(buf, 1, SIZE, stdin);
    			bi = 0;
    		}
    		s[sn] = 0;
    		return sn;
    	}
    	bool read(int& x) {
    		int n = read(str), bf;
    
    		if (!n) return 0;
    		int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;
    		for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
    		if (bf < 0) x = -x;
    		return 1;
    	}
    };
    

    使用方法

    在本地运行是看不到输出结果的,需要在文件中查看,但是交到oj上是不需要把结果写在文件中的
    使用实例 POJ1000 A+B

    #include<iostream>
    #include<cstdio>
    using namespace std;
    #define fin freopen("in.txt", "r", stdin)
    #define fout freopen("out.txt", "w", stdout)
    #define FI(n) FastIO::read(n)
    namespace FastIO {
    	const int SIZE = 1 << 16;
    	char buf[SIZE], obuf[SIZE], str[60];
    	int bi = SIZE, bn = SIZE, opt;
    	int read(char *s) {
    		while (bn) {
    			for (; bi < bn && buf[bi] <= ' '; bi++);
    			if (bi < bn) break;
    			bn = fread(buf, 1, SIZE, stdin);
    			bi = 0;
    		}
    		int sn = 0;
    		while (bn) {
    			for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
    			if (bi < bn) break;
    			bn = fread(buf, 1, SIZE, stdin);
    			bi = 0;
    		}
    		s[sn] = 0;
    		return sn;
    	}
    	bool read(int& x) {
    		int n = read(str), bf;
    
    		if (!n) return 0;
    		int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;
    		for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
    		if (bf < 0) x = -x;
    		return 1;
    	}
    };
    
    int main()
    {
      //fout; 
      int a,b;
      FI(a),FI(b);
      printf("%d
    ",a+b);
    }
    
    
  • 相关阅读:
    WPF Path和图形
    WPF学习笔记:(二)数据绑定模式与INotifyPropertyChanged接口
    WPF学习笔记:(一)数据绑定与DataContext
    IOC 的理解与解释
    WPF入门教程系列(二) 深入剖析WPF Binding的使用方法
    WPF入门教程系列(一) 创建你的第一个WPF项目
    一、什么是WPF?
    项目问题一、全局变量引起的并发问题
    常用js操作
    escape
  • 原文地址:https://www.cnblogs.com/llke/p/10831646.html
Copyright © 2011-2022 走看看