Input and Output Method

  IO stands for input and output in programming.

  IO is important in programming, especially in Olympic Informatic, due to the policy of it. Therefore, as a contestant in Olympic Informatic, it‘s neccesary for me to sumarize the method of IO, in order to make my programs run more rapidly.

  Generally speaking, I classify the methods according to the real situation, containing the simple systematic one and the faster systematic one. Which one to use decides on the amount of data.

The Simple Systematic Methods

  Read a char c:  c = getchar();

  Read a char wanted:

inline char rdc(void) {
    char c = getchar();
    while (!isalpha(c); c=getchar());
    return c;
}

  Print a char c:  putchar(c);

  Read a integer x:  scanf("%d", &x);

  Print a integer x:  printf("%d", x);

  Read a string s:  scanf("%s", s+1);

  Print a string s:  printf("%s\n", s+1);

The Faster Systematic Methods

  The system is used to input integers, char, and output integer, char and string.

  The main idea is to read all data in strings and then transfer it , through using fread and fwrite

  Input char and integer:

namespace Input {
    const int S = 2000000;
    char s[S]; char *h = s+S, *t = h;
    inline char getchr(void) { if (h == t) fread(s, 1, S, stdin), h = s; return *h++; }
    inline char rdc(void) { char c = getchr(); while (!isalpha(c)) c = getchr(); return c; }
    inline int rd(void) {
        int x = 0, f = 1; char c = getchr(); for (; !isdigit(c); c = getchr()) if (c == ‘-‘) f = -1;
        for (; isdigit(c); c = getchar()) x = x*10+c-‘0‘; return x*f;
    }
}
using Input::getchr;
using Input::rdc;
using Input::rd;

  Output integer, char and string:

namespace Output {
    const int S = 2000000;
    char s[S]; char *t = s;
    inline void Add(char c) { *t++ = c; }
    inline void put(int x) {
        if (!x) { Add(‘0‘), Add(‘\n‘); return; }
        if (x < 0) Add(‘-‘), x = -x;
        static int a[70]; int len = 0;
        for (; x > 0; x /= 10) a[++len] = x%10;
        while (len > 0) Add(‘0‘ + a[len--]);
        Add(‘\n‘);
    }
    inline void Flush(void) { fwrite(s, 1, t-s, stdout); }
}
using Output::Add;
using Output::put;
using Output::Flush;

  This is the first time that I use English to write an article. It may be really a challenge for me, but bring me with pleasure and happiness !

时间: 2024-12-21 04:40:34

Input and Output Method的相关文章

spring cloud Stream input和output重名报错

目前项目是用的springboot 2.0.5.RELEASE,版本号为:Finchley.SR2客户端测试代码如下: import org.springframework.cloud.stream.annotation.Input; import org.springframework.cloud.stream.annotation.Output; import org.springframework.messaging.MessageChannel; import org.springfra

[20160704]Addition program that use JOptionPane for input and output

1 //Addition program that use JOptionPane for input and output. 2 3 import javax.swing.JOptionPane; 4 5 public class Addition{ 6 public static void main(String[] args) { 7 String firstNumber=JOptionPane.showInputDialog("Enter first integer!"); 8

File Input and Output

Use of File Stream Assume ifle and ofile is the string object storing the names of input and output files' namess. string ifile = "inputFile.txt"; string ofile = "outputFile.txt"; Then the use of file stream is like this: // construct

标准库 - 输入输出处理(input and output facilities) lua

标准库 - 输入输出处理(input and output facilities)责任编辑:cynthia作者:来自ITPUB论坛 2008-02-18 文本Tag: Lua [IT168 技术文档]I/O库提供两种不同的方式进行文件处理1.io表调用方式:使用io表,io.open将返回指定文件的描述,并且所有的操作将围绕这个文件描述 io表同样提供三种预定义的文件描述io.stdin,io.stdout,io.stderr2.文件句柄直接调用方式,即使用file:XXX()函数方式进行操作,

转载:Pixhawk源码笔记四:学习RC Input and Output

转自:新浪@WalkAnt 第五部分 学习RC Input and Output 参考:http://dev.ardupilot.com/wiki/learning-ardupilot-rc-input-output/ RC Input,也就是遥控输入,用于控制飞行方向.改变飞行模式.控制摄像头等外围装置.ArduPilot支持集中不同RC input(取决于具体的硬件飞控板): 1. PPMSum – on PX4, Pixhawk, Linux and APM2 2. SBUS – on P

Python Tutorial 学习(七)--Input and Output

7. Input and Output Python里面有多种方式展示程序的输出.或是用便于人阅读的方式打印出来,或是存储到文件中以便将来使用.... 本章将对这些方法予以讨论. 两种将其他类型的值转换为字符型值的方法:repr()和str(),二者的区别在于,一个是给机器读的,一个是给人读的,str()返回的是更适合人阅读的样式 一些栗子: >>> s = 'Hello, world.' >>> str(s) 'Hello, world.' >>>

angular 的 @Input、@Output 的一个用法

angular 使用 @input.@Output 来进行父子组件之间数据的传递. 如下: 父元素: <child-root parent_value="this is parent value" (child_emit)="test()"></child-root> 父元素标签中有一个属性是,parent_value,在子元素中可以使用该值: <p [title]="parent_value" >this p

input和output常用模块的讲解和使用(logstash)

1 ELK 是一个实时分布式的日志分析平台ELK 是一整套的解决方案(E)lasticsearch -- 数据库(L)ogstash -- 收集日志.标准化的程序(K)ibana -- 图形的展示工具 2 数据批量导入-X 导入使用的方法 POST--data-binary 导入数据的格式@urfile 导入数据的文件名_bulk 导入关键字curl -X "POST" "http://192.168.1.13:9200/_bulk" --data-binary @

C lang:character input and output

Xx_Introduction Character input and output is by more line character conpose of the text flow  Define name common use capital  letter,easy read. The Standard C Library ----->provide I/O model ------>use character flow way. Ax_Application file copy,c