为什么超快读会 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 ttq012 @ 2024-12-09 21:26:07

@guoj(如果我没记错的话),好像是合法为任意非零数,不合法为 0

也就是说如果这么定义 isdigit 函数也是合法的

int my_isdigit(char x) {
  if (x >= '0' && x <= '9') return rand() + 1;
  return 0;
}

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

(顺带一提 isdigit 函数返回值是 int)


by guoj @ 2024-12-09 21:30:57

@ttq012 好像确实有


by luoguplay @ 2025-01-04 16:01:37


#include <iostream>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  cout << a + b;
}

上一页 |