快速IO题解

jhhk77 2020-11-21 22:54:36 2021-03-28 11:00:49 9 返回题目

题目大意


就是输出 个数加上 后的结果。

分析


这道题明显不可以用 ),实际上用 都不太合适(时间限制从原来的 调到了 ),正解应该是快速读入与快速输出。

快读快输实际上利用的是 读入输出的速度大于

上代码。

AC代码


#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x = 0;
    bool f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-'){
            f = -1; //标记为负数
        }
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return f == 1 ? x : -x;
}
inline void write(int x){
    char f[21];
    int len = 0;
    if(x < 0){
        putchar('-');
        x = -x;
    }
    else if(x == 0){
        putchar('0'); //特判x=0
        return;
    }
    while(x > 0){
        f[++len] = x % 10 + '0';
        x /= 10;
    }
    while(len){
        putchar(f[len--]);
    }
}
int n, a[3000001];
int main(){
    n = read();
    for(int i = 1;i <= n;++i) {
        a[i] = read();
    }
    for(int i = 1;i <= n;++i) {
        write(a[i] + 1);
        putchar(' ');
    }
    return 0;
}
{{ vote && vote.total.up }}

共 1 条回复

cookiebus

👍