题解 P1001 【A+B Problem 】

· · 题解

/* * P: 1001

* Au: Small_Ash

* 表示我稍微加上了一个读入和输出优化。。。。

* 为什么要占坑呢,主要是发一下读入输出优化的代码

* 顺便给新生们传授一下c++超快的读入输出方法。。。

* 一般来说,c++有三种读入方式 scanf cin 以及读入优化。。。

* cin 在加上ios优化之前是很慢的 scanf其次 读入优化(read)最快

* 以下是我做的测试数据

* 当读入从1开始到10^7的数列数据时:

* cin耗时6.02s,scanf耗时2.23s,read只耗时0.58s

* 同理 cont>scanf>输出优化

* 对付大数据的题目这是可以用的(前提是数据输入输出都是纯数据,没有符号【包括英文字母】)

* 新生可以先不用弄懂实现原理,直接背就行了。这些优化NOIP是可以用的。

* 下面是代码

*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int read(){
    int out=0,fh=1;
    char cc=getchar();
    if (cc=='-') fh=-1;
    while (cc>'9'||cc<'0') cc=getchar();
    while (cc>='0'&&cc<='9') {out=out*10+cc-'0';cc=getchar();}
    return out*fh;
}
void write(int x)  
{  
    if (x==0){
        putchar('0');
        return;
    }
    int num = 0; char c[15];
    while(x) c[++num] = (x%10)+48, x /= 10;
    while(num) putchar(c[num--]);
    putchar(' '); 
}
int main(){
    write(read()+read());
    return 0;
}