[模拟]JZOJ 5820 非法输入
分析
这题按照题意模拟即可,要注意的有:单个零,前导零,-0,以及行间末符号等
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; ll a,b; int t; char c; ll Read() { c=getchar();ll num=0,p=1; bool q=0; while (c>'9'||c<'0') { if (c=='-'&&p>0) p=-1; else return 2147483648ll; c=getchar(); } if (c=='0'&&p==-1) return 2147483648ll; if (c=='0') q=1; while ('0'<=c&&c<='9') { num=num*10+c-'0'; if (num>2147483648ll) return 2147483648ll; if ('0'>c||'9'<c) return 2147483648ll; c=getchar(); if ('0'<=c&&c<='9'&&q) return 2147483648ll; } if (c!=' '&&c!='\n') return 2147483648ll; return num*p; } int main() { freopen("aplusb.in","r",stdin); freopen("aplusb.out","w",stdout); scanf("%d\n",&t); while (t--) { a=Read(); if (a>2147483647ll||a<-2147483648ll||c=='\n') { printf("Input Error\n"); while (c!='\n') c=getchar(); continue; } b=Read(); if (c!='\n') b=2147483648ll; if (b>2147483647ll||b<-2147483648ll) { printf("Input Error\n"); while (c!='\n') c=getchar(); continue; } printf("%lld\n",a+b); } fclose(stdin);fclose(stdout); }
在日渐沉没的世界里,我发现了你。