@[right_cat](/space/show?uid=76561) ``ull`` 也不可以 需要判一下长度是不是合法才行
另外还有别的错误
by 一扶苏一 @ 2019-03-19 16:45:16
@[一扶苏一](/space/show?uid=65363) 改了还是不行,真的不清楚哪里错了。
这里是改后的代码:
```cpp
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
long long L, R;
int T;
inline bool cc1(string x) {
if(x[0] != '-' && !(x[0] >= '1' && x[0] <= '9'))
return true;
int len = x.size();
if(x[0] == '-') {
if(!(x[1] >= '1' && x[1] <= '9')) return true;
for(int i = 1; i < len; i++)
if(!(x[i] >= '0' && x[i] <= '9')) return true;
} else {
for(int i = 1; i < len; i++)
if(!(x[i] >= '0' && x[i] <= '9')) return true;
}
return false;
}
inline int cc2(string x) {
int len = x.size();
if(!cc1(x)) {
if(x[0] == '-' && len > 20) return 2;
if(x[0] != '-' && len > 19) return 2;
long long t = atoi(x.c_str());
if(t < L || t > R) return 2;
}
return 0;
}
int main() {
scanf("%lld %lld %d", &L, &R, &T);
string x;
int ans;
while(T--) {
cin >> x;
if(x == "0") {printf("0\n"); continue;}
ans = cc1(x) + cc2(x);
printf("%d\n", ans);
}
}
```
by right_cat @ 2019-03-19 17:34:56
应该是这个
```cpp
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
long long L, R;
int T;
inline bool cc1(string x) {
if(x[0] != '-' && !(x[0] >= '1' && x[0] <= '9'))
return true;
int len = x.size();
if(x[0] == '-') {
if(!(x[1] >= '1' && x[1] <= '9')) return true;
for(int i = 1; i < len; i++)
if(!(x[i] >= '0' && x[i] <= '9')) return true;
} else {
for(int i = 1; i < len; i++)
if(!(x[i] >= '0' && x[i] <= '9')) return true;
}
return false;
}
inline int cc2(string x) {
int len = x.size();
if(!cc1(x)) {
if(x[0] == '-' && len > 20) return 2;
if(x[0] != '-' && len > 19) return 2;
unsigned long long t = atoi(x.c_str());
if(t < L || t > R) return 2;
}
return 0;
}
int main() {
scanf("%lld %lld %d", &L, &R, &T);
string x;
int ans;
while(T--) {
cin >> x;
if(x == "0") {printf("0\n"); continue;}
ans = cc1(x) + cc2(x);
printf("%d\n", ans);
}
}
```
by right_cat @ 2019-03-19 17:35:45
@[right_cat](/space/show?uid=76561) 您用 ``unsigned long long`` 存的话如果给的是负数不就凉了
by 一扶苏一 @ 2019-03-19 18:47:19
long double
by FanSizhe127 @ 2021-10-28 13:00:44