HDU 1554(Pairs of integers)

#include <iostream>
#include <map>
#include <iomanip>
using namespace std;

int N;
int H, S, L;
int X;
map<int, int> res, ri;

int main()
{
	while (cin >> N)
	{
		res.clear();
		ri.clear();
		for (int i = 0, num = 1; num <= N; i++, num *= 10)
		{
			if (N % num % 2 != 0)
				continue;
			H = N / num / 11;
			S = N / num % 11;
			L = N % num / 2;
			if (S <= 9) 
			{
				X = (H * 10 + S) * num + L;
				if (H + S) 
					res[X] = H * num + L;
				ri[X] = i;
			}
			L = (N % num + num) / 2;
			S = N / num % 11 - 1;
			if (S >= 0 && L) 
			{
				X = (H * 10 + S) * num + L;
				if (H + S) 
					res[X] = H * num + L;
				ri[X] = i;
			}
		}
		cout << res.size() << endl;
		for (map<int, int>::iterator it = res.begin(); it != res.end(); it++)
			cout << it->first << " + " << setw(ri[it->first]) << setfill('0') << it->second << " = " << N << endl;
	}
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章