玄学错误,求高人指点
查看原帖
玄学错误,求高人指点
739448
jkfof楼主2024/9/29 15:56
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

LL n;

LL read() {
	LL ans = 0, op;
	char c;
	c = getchar();
	if (c == '-')op = -1;
	else op = 1, ans = c - '0';
	do {
		c = getchar();
		ans = ans * 10 + c - '0';
	} while (c <= '9' && c >= '0');
	ans = (ans - ((LL)c - '0')) / 10;
	return ans * op;
}

LL sum, idx;
char zong[111];
void write() {
	LL &x = sum;
	if (x < 0)putchar('-'), x = -1 * x;
	do {
		zong[idx++] = (x % 10) + '0';
		x /= 10;
	} while (x);

	for (LL i = idx - 1; i > -1; --i) {
		putchar(zong[i]);
	}

}

int main() {

	n = read();

	while (n--) {
		sum += read();
	}

	write();

	return 0;
}

先前按照自己思路打的,自己试过对拍,试过构造大数据,但都对,但本题的测试点前三个WA了(第四个点因为用的getchar是TLE)

2024/9/29 15:56
加载中...