PAT-练习集-L1-025. 正整数A+B
来源:互联网 发布:学linux能干哪些工作 编辑:程序博客网 时间:2024/04/26 13:09
传送门:https://www.patest.cn/contests/gplt/L1-025#include <cstdio>#include <string.h>#include <iostream>#include <algorithm>#include <stack>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#define REP(i,k,n) for(int i=k;i<n;i++)#define REPP(i,k,n) for(int i=k;i<=n;i++)#define scan(d) scanf("%d",&d)#define scann(n,m) scanf("%d%d",&n,&m)#define mst(a,k) memset(a,k,sizeof(a));#define LL long long#define mod 1000000007#define ls (g<<1)#define rs (g<<1|1)#define PI acos(-1.0)#define INF 0x6f6f6f6fusing namespace std;#define LL long long#define N 10005/*题意:注意:我们把输入中出现的第1个空格认为是A和B的分隔。题目保证至少存在一个空格,并且B不是一个空字符串。这个提示的用意是告诉我们,第一个空格之后的字符都属于B,则有:1 1 (之间两个空格)得到 1 + ? = ?*/string s;string tmp1="",tmp2=""; // 两个字符串bool check(string s) // 判断字符串是否满足要求{ int len = s.length(); int sum=0; if(len>4) return 0; // 不可能超过4位数 for(int i=0;i<len;i++){ if(s[i]>='0' && s[i]<='9') sum=sum*10+s[i]-'0'; else return 0; // 只可能是数字 } if(sum>1000) return 0; // 结果在[1,1000] if(sum==0) return 0; return 1;}int get(string s){ int sum = 0; for(int i=0;i<s.length();i++){ sum = sum * 10 + s[i] - '0'; } return sum;}int main(){ getline(cin,s); int len = s.length(); int cot = 0; bool flag = 0; for(int i=0;i<len;i++){ if(s[i]==' '&&!flag){ //第一次出现空格,分隔两个字符串 cot++; flag = 1; continue; } if(cot==0) tmp1+=s[i]; else if(cot==1) tmp2+=s[i]; } if(check(tmp1)) cout<<tmp1; else cout<<"?"; cout<<" + "; if(check(tmp2)) cout<<tmp2; else cout<<"?"; cout<<" = "; if(check(tmp1)&&check(tmp2)) cout<<get(tmp1)+get(tmp2); else cout<<"?"; return 0;}
1 0
- PAT-练习集-L1-025. 正整数A+B
- pat L1-025. 正整数A+B
- PAT L1-025. 正整数A+B
- [PAT][GPLT][CCCC]L1-025.正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- L1-025. 正整数A+B
- 【第11题】360校园招聘2015届技术类笔试题
- android蓝牙4.0的知识要点
- 【第12题】360校园招聘2015届技术类笔试题
- Lambda&Java多核编程-5-函数式接口与function包
- POJ3709 K-Anonymous Sequence(k匿名序列)(斜率优化dp)
- PAT-练习集-L1-025. 正整数A+B
- leetcode [Sqrt(x)]
- codeforces 782B
- C语言 strnlen函数实现
- 【第13题】360校园招聘2015届技术类笔试题
- Android注解使用之ButterKnife 8.0注解使用介绍
- 【贪心算法】最少拦截系统
- 重温数据结构一
- CSS中的背景用法大全