#大佬救救!自己测试是对的,但是前五个一直RE!救救!

P1553 数字反转(升级版)

@[ababcrrr](/user/879389) 测试数据不保证有 `'\n'`
by MarchKid_Joe @ 2023-01-31 21:09:36


@[ababcrrr](/user/879389) 然后就是会爆 `long long` 的数据范围,因为 $1e20>2^{63}-1$
by MarchKid_Joe @ 2023-01-31 21:11:52


这个可以得到 95,因为有一个测试点爆 `long long` 了。 ```cpp #include<stdio.h> #include<stdlib.h> long long zhuan(long long n) { long long i, j, x=0; if (n == 0)return 0; i = n; j = i % 10; while (j == 0) { i = i / 10; j = i % 10; } while (i != 0) { x = x * 10 + j; i = i / 10; j = i % 10; } return x; } int main() { char ch[1000] = { 0 },sh[1000]={0}; long long i, j=1, sum = 0, x,y; i = 0; ch[i] = getchar(); for (i = 1;i <= 20; i++) { ch[i] = getchar(); if (ch[i] == '.') { sh[0] = '.'; ch[i] = '\0'; x = (atoll)(ch); scanf("%lld", &y); while (y!=0&&y % 10 == 0) { y = y / 10; sh[j] = '0'; j++; } printf("%lld%s%lld", zhuan(x),sh, zhuan(y)); return 0; } if (ch[i] == '/') { sh[0] = '/'; ch[i] = '\0'; x = (atoll)(ch); scanf("%lld", &y); printf("%lld%c%lld",zhuan(x),sh[0], zhuan(y)); return 0; } if (ch[i] == '%') { x = 1; sh[0] = '%'; ch[i] = '\0'; x = (atoll)(ch); printf("%lld%c",zhuan(x),sh[0]); return 0; } } x = (atoll)(ch); printf("%lld", zhuan(x)); return 0; } ```
by MarchKid_Joe @ 2023-01-31 21:12:47


@[ababcrrr](/user/879389) 但是可以使用 `unsigned long long`,可以通过。 AC Code ```cpp #include<stdio.h> #include<stdlib.h> #include <bits/stdc++.h> using namespace std; long long zhuan(long long n) { long long i, j, x=0; if (n == 0)return 0; i = n; j = i % 10; while (j == 0) { i = i / 10; j = i % 10; } while (i != 0) { x = x * 10 + j; i = i / 10; j = i % 10; } return x; } int main() { char ch[1000] = { 0 },sh[1000]={0}; long long i, j=1, sum = 0, x,y; i = 0; ch[i] = getchar(); for (i = 1;i <= 20; i++) { ch[i] = getchar(); if (ch[i] == '.') { sh[0] = '.'; ch[i] = '\0'; x = (atoll)(ch); scanf("%lld", &y); while (y!=0&&y % 10 == 0) { y = y / 10; sh[j] = '0'; j++; } printf("%lld%s%lld", zhuan(x),sh, zhuan(y)); return 0; } if (ch[i] == '/') { sh[0] = '/'; ch[i] = '\0'; x = (atoll)(ch); scanf("%lld", &y); printf("%lld%c%lld",zhuan(x),sh[0], zhuan(y)); return 0; } if (ch[i] == '%') { x = 1; sh[0] = '%'; ch[i] = '\0'; x = (atoll)(ch); printf("%lld%c",zhuan(x),sh[0]); return 0; } } unsigned long long _x = 0; for (int i = 20; i >= 0; i--) if (ch[i] >= '0' && ch[i] <= '9') _x = _x * 10 + ch[i] - '0'; printf("%llu", _x); return 0; } ```
by MarchKid_Joe @ 2023-01-31 21:19:48


@[MarchKid_Joe](/user/239163) 哇哇哇感谢大佬!!
by goallllout @ 2023-02-01 21:08:57


|