Jesus!!!! 本来很easy,卡在test 3.
这是因为AB间的分隔符(delimiter)有且仅有一个空格.也就是说B的开头可以是space
Solution:
第一个用的string:: find_first_of(' ');
刚学正则表达式regular expression,感觉会更好.
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>
#include<unordered_set>
using namespace std;
#define fo(i,n) for(int i=1;i<=n;++i)
int bb, aa;
#define int long long
signed main()
{
string par;
getline(cin, par);
int fpos = par.find_first_of(' ');
//cout<<fpos<<'\n';
string sa(par.begin(), par.begin() + fpos);
string sb(par.begin() + fpos + 1, par.end());
int lena = 0, lenb = 0;
int flaga = 1;
for (auto i : sa)
{
if (i < '0' || i > '9')
{
flaga = 0;
}
}
if (!flaga)
{
sa = '?';
}
else
{
for (auto i : sa)
{
aa *= 10;
aa += i - '0';
}
if (aa > 1000 || aa == 0)sa = '?', flaga = 0;
}
int flagb = 1;
for (auto i : sb)
{
if (i < '0' || i > '9')
{
flagb = 0;
}
}
if (!flagb)
{
sb = '?';
}
else
{
for (auto i : sb)
{
bb *= 10;
bb += i - '0';
}
if (bb > 1000 || bb == 0)sb = '?', flagb = 0;
}
if (!flaga || !flagb)
{
cout << sa << " + " << sb << " = " << '?';
}
else
{
cout << sa << " + " << sb << " = " << aa + bb;
}
return 0;
}