Rezultati

Up. imeNalogaJezikRezultatČas oddaje
rektifikatorji-2018 Sveti gral C++ 100/100OK 10. maj '18 @ 17:47

Test Točke Porabljen spomin Porabljen čas Status
#1 5/5 3,398 MiB 0,004 s OK
#2 5/5 3,398 MiB 0,004 s OK
#3 5/5 3,168 MiB 0,004 s OK
#4 5/5 3,223 MiB 0,004 s OK
#5 5/5 3,227 MiB 0,004 s OK
#6 5/5 3,227 MiB 0,004 s OK
#7 5/5 3,395 MiB 0,004 s OK
#8 5/5 3,457 MiB 0,004 s OK
#9 6/6 3,398 MiB 0,004 s OK
#10 6/6 3,398 MiB 0,004 s OK
#11 6/6 3,227 MiB 0,004 s OK
#12 6/6 3,223 MiB 0,004 s OK
#13 6/6 3,395 MiB 0,004 s OK
#14 6/6 3,398 MiB 0,000 s OK
#15 6/6 3,398 MiB 0,004 s OK
#16 6/6 3,457 MiB 0,004 s OK
#17 6/6 3,457 MiB 0,000 s OK
#18 6/6 3,219 MiB 0,000 s OK

Ocenjevani program (Source.cpp):
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

inline int digit_cnt(int x)
{
	if (x == 0)
		return 1;
	return (int)ceil(log10(x + 1));
}

inline int digitAt(int x, int div)
{
	return (x / div) % 10;
}

int main()
{
	int n;
	cin >> n;



	int x_min = max(n - digit_cnt(n) * 9, 1);
	int x_max = max(n - 1, 0);

	vector<int> xs;
	//xs.reserve(x_max - x_min + 1);
	for (int x = x_min; x <= x_max; x++)
	{
		int x_len = digit_cnt(x);

		int sum = x;
		int div = 1;
		for (int i = 0; i != x_len; i++)
		{
			sum += digitAt(x, div);
			div *= 10;
		}

		if (n == sum)
			xs.push_back(x);
	}

	cout << xs.size() << endl;
	for (int i = 0; i != xs.size(); i++)
	{
		cout << xs[i] << endl;
	}

	//system("pause");
}