题目链接

https://www.patest.cn/contests/gplt/L1-025

思路

注意 输入字符串B的时候 要用getline 因为 可能存在空格

然后就把字符串 转化成 数字 并且判断一下 范围和 是否含有非法字符 就可以了

AC代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std; typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int f(string s)
{
int len = s.size();
int i;
int num = 0;
if (s[0] == '0')
return -1;
for (i = 0; i < len; i++)
{
if (s[i] <= '9' && s[i] >= '0')
num = num * 10 + (s[i] - '0');
else
{
return -1;
}
}
return num;
} int main()
{
string a, b;
cin >> a;
getchar();
getline(cin, b);
int n = f(a);
int m = f(b);
if (n >= 1 && n <= 1000 && m >= 1 && m <= 1000)
printf("%d + %d = %d\n", n, m, n + m);
else if(n <= 1000 && n >= 1)
printf("%d + ? = ?\n", n);
else if (m <= 1000 && m >= 1)
printf("? + %d = ?\n", m);
else
printf("? + ? = ?\n");
}

最新文章

  1. Asp.Net Core 发布和部署(Linux + Jexus )
  2. CSS中伪类及伪元素用法详解
  3. JSONKit does not support Objective-C Automatic Reference Counting(ARC) / ARC forbids Objective-C objects in struct
  4. 【BZOJ-4326】运输计划 树链剖分 + 树上差分 + 二分
  5. xcode代码提示功能失效的解决方法
  6. SQL查询语句执行的顺序是-----------------
  7. 从源代码分析Universal-Image-Loader中的线程池
  8. awk 例子
  9. pager分页框架体会
  10. ACM 数论小结 2014-08-27 20:36 43人阅读 评论(0) 收藏
  11. 【POJ】【1067】取石子游戏
  12. Filter登录验证过滤器(全局)
  13. thinkphp3.2.3 成功对接支付宝接口
  14. 5 HBase 常用Shell命令
  15. poj1804(归并排序求逆序数)
  16. Python中三种基本结构的语句
  17. TDE: Transparent Data Encryption brief introduction
  18. Android onclick监听事件打开新界面
  19. iOS 隐藏导航条分割线
  20. Block高级用法:Block传值UI_12(3)

热门文章

  1. cf #363 b
  2. Android 四大组件学习之Service六
  3. Android.mk 输出日志 调试
  4. 浅谈DNS
  5. MySQL的having子句
  6. spring无法启动常见原因及排查方法
  7. Android无线测试之—UiAutomator UiDevice API介绍五
  8. iphone客户端上传图片到服务器
  9. JQuery实现动态生成树形菜单
  10. conda 和 pip 安装,更新,删除