Kathang artifact--register with fast read-in output

Source: Internet
Author: User

Quick read in Template
int read() {    int s = 0, w = 1;    char ch = getchar(); //getchar() 一次从键盘读入一个字符    while (ch <=‘0‘ || ch > ‘9‘) {        if (ch == ‘-‘) w = -1;        ch = getchar();    }    while (ch >= ‘0‘ && ch <= ‘9‘) {        s = s * 10 + ch - ‘0‘;        ch = getchar();    }    return s * w;}
Quick Output Template
inline void write(int x) { // inline 可以防止爆栈,虽然现在一般不太会    if (x < 0) putchar(‘-‘), x = -x;    if (x > 9) write(x / 10);    putchar(x % 10 + ‘0‘);}
Register

Register is the meaning of the CPU register, the variables in this is much faster than in memory, so think of the variables in the following for loop i can be declared when the variable register can be added to make the for loop much faster. However, register the space is very small, usually just a few megabytes, the server CPU may be larger. If the register is out of use, even if your variable is declared, register it will not be placed in the register.

for (register int i = 1; i <= 1000000; ++i) {    printf("%d\n", i);}

Kathang artifact--register with fast read-in output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.