原题:
没考虑大数问题(数字位数太长,double不够大或不够精细),用字符串处理比较好,不过懒得重新写一遍。
以下是没考虑大数问题代码:
#include<iostream>
#include<string>
using namespace std;
double first = 0, second = 0;
double temp=0,n=0,point=0;
bool judge(double first, double second, double N)
{
if (first > 10 && second > 10 && (first == N || second == N || first + second == N))
return true;
else
return false;
}
void spilt(string str, int begin, int end, double N)
{
if (begin > end)
cout << "false"<<endl;
else if (str[begin] == ',')
{
first = second;
if (point==0)
second = temp;
else
{
second = temp ;
point = 0;
}
//cout << first << second << endl;
bool res = judge(first, second,N);
if (res)
{
cout << "true" << endl;
}
else
{
temp = 0;
point = 0;
spilt(str, begin + 1, end,N);
}
}
else if (str[begin] == '.')
{
point = 1;
spilt(str, begin + 1, end, N);
}
else
{
if (point==0)
temp = temp * 10 + str[begin] - '0';
else
{
point *= 10;
temp = temp + (str[begin] - '0') / point;
}
spilt(str,begin+1,end,N);
}
}
int main()
{
string str;
double N;
getline(cin, str);
cin >> N;
/*cout << str << endl;
cout << N;*/
str = str + ",";
spilt(str,0,str.length()-1,N);
system("pause");
return 0;
}