美文网首页
==京东内推-神奇数-c++

==京东内推-神奇数-c++

作者: Jacinth | 来源:发表于2017-09-09 08:34 被阅读0次

include <iostream>

include <cstdio>

include <cstring>

include <cmath>

include <map>

include <string>

include <vector>

include <set>

include <queue>

include <deque>

include <stack>

include <algorithm>

include <unordered_map>

using namespace std;

bool valid(vector<int> digits)
{
sort(digits.begin(), digits.end());
int sum1 = 0, sum2 = 0;
for(unsigned int i=0; i < digits.size();i++)
{
if (sum2 <= sum1)
{
sum2 += i;
}
else
{
sum1 += i;
}
}
return sum1 == sum2;
}

int main()
{
int l, r;
while (cin >> l >> r)
{
int cnt = 0;
for (int i = l; i <= r; ++i)
{
vector<int> digits;
int num = i;
while (num)
{
int d = num % 10;
digits.push_back(d);
num /= 10;
}
if (valid(digits))
cnt++;
}
cout << cnt << endl;
}
system("PAUSE");
return 0;
}

相关文章

网友评论

      本文标题:==京东内推-神奇数-c++

      本文链接:https://www.haomeiwen.com/subject/kkdojxtx.html