#include <stdio.h>
	#include <stdbool.h>
	#include <string.h>

	const char* units[] = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};
	const char* tens[] = {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "C"};
	const char* hundreds[] = {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "M"};
	const char* symbols = "IVXLCDM";

	void to_roman(int number, char *result);
	bool has_one(const char *haystack, char needle);
	int main(void)
	{
		for(int number = 1; number < 2000; number++)
		{
			bool ok = true;
			char roman[100];
			to_roman(number, roman);
			for(int s = 0; symbols[s]; s++)
			{
				if(!has_one(roman, symbols[s]))
				{
					ok = false;
					break;
				}
			}
			if(ok)
				printf("%d : %s\n", number, roman);
		}
		return 0;
	}

	bool has_one(const char *haystack, char needle)
	{
		int count = 0;
		for(int i = 0; haystack[i]; i++)
			if(haystack[i] == needle && ++count == 2)
				return false;
		return count == 1;
	}

	void to_roman(int number, char *result)
	{
		int M = (number / 1000) % 10;
		int C = (number / 100) % 10;
		int X = (number / 10) % 10;
		int I = (number / 1) % 10;
		result[0] = '\0';
		if(M != 0)
			strcat(result, "M");
		if(C != 0)
			strcat(result, hundreds[C - 1]);
		if(X != 0)
			strcat(result, tens[X - 1]);
		if(I != 0)
			strcat(result, units[I - 1]);
	}