为什么超快读会 RE?

P1001 A+B Problem

Laugh_at_the_sky @ 2024-12-09 20:56:48

#include <iostream>

using namespace std;

char buf[1 << 20], *_now = buf, *_end = buf;
#define getchar() (_now == _end && (_end = (_now = buf) + fread(buf, 1, 1 << 20, stdin), _now == _end) ? EOF : *_now++)

int input() {
    int x = 0, f = 1;
    char ch = getchar();
    while (isdigit(ch) ^ 1) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }

    return x * f;
}

void solve() {
    int A = input(), B = input();
    cout << A + B << "\n";
}

int main() { solve(); }

by Laugh_at_the_sky @ 2024-12-09 20:57:43

RT,把超快读的宏定义去掉就能 AC


by 缪凌锴_Mathew @ 2024-12-09 20:59:29

fread 真的是 iostream 的吗


by Laugh_at_the_sky @ 2024-12-09 21:04:16

加上 cstdio 也会 RE@缪凌锴_Mathew


by wangsiyuanZP @ 2024-12-09 21:04:34

@Laugh_at_the_sky main 没有 return 0


by Laugh_at_the_sky @ 2024-12-09 21:05:52

加上 return 0 还是 RE


by Laugh_at_the_sky @ 2024-12-09 21:06:17

而且 C++ 的 main 不是默认返回 0 吗


by Laugh_at_the_sky @ 2024-12-09 21:06:29

@wangsiyuanZP


by ttq012 @ 2024-12-09 21:08:39

@Laugh_at_the_sky

您好,把 _now_end 变量的赋值去掉即可 AC

(还有就是isdigit函数返回的值好像不一定必须是0或1)


by guoj @ 2024-12-09 21:17:23

@ttq012 是0或1

#include<bits/stdc++.h>
using namespace std;
int main(){
    char a;
    cin>>a;
    cout<<isdigit(a);
}

by ttq012 @ 2024-12-09 21:24:48

@guoj 我记得好像有系统差异的说


| 下一页