All pastes #837717 Raw Edit

Anonymous

public text v1 · immutable
#837717 ·published 2007-12-29 21:36 UTC
rendered paste body
#include <iostream>
#include <sstream>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#include <boost/assign/std/vector.hpp>
#include <boost/assign/std/map.hpp>

using std::string;
using std::map;
using std::vector;
using namespace boost::assign;

string SpellEn(int num) {
	if (num<0) {
		return "minus " + SpellEn(-num);
	}

	if (num<=19) {
		vector<string> w;
		w += "zero", "one", "two", "three", "four", "five", "six", "seven",	"eight", "nine", "ten"
			, "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen";
		return w.at(num);
	}

	if (num<=99) {
		vector<string> w;
		w += "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety";
		int ten = (num/10);
		int one = num%10;
		return 
			w.at(ten-2) 
			+ ((one!=0) ? ("-"+SpellEn(one)) : (""));
	}

	if (num<=999) {
		int hundred = num / 100;
		int rest = num % 100;
		return 
			SpellEn(hundred) + " hundred" 
			+ ((rest!=0) ? (" "+SpellEn(rest)) : (""));
	}

	if (num<=99*999) {
		int thousand = num / 1000;
		int rest = num % 1000;
		return 
			SpellEn(thousand) + " thousand" 
			+ ((rest!=0) ? (" "+SpellEn(rest)) : (""));
	}

	return "???";
}


string SpellPl(int num) {
	if (num<0) {
		return "minus " + SpellPl(-num);
	}

	if (num<=19) {
		vector<string> w;
		w += "zero", "jeden", "dwa", "trzy", "cztery", "pięć", "sześć", "siedem",	"osiem", "dziewięć", "dziesięć"
			, "jedenaście", "dwanaście", "trzynaście", "czternaście", "piętnaście", "szesnaście", "siedemnaście", "osiemnaście", "dziewiętnąscie";
		return w.at(num);
	}

	if (num<=99) {
		vector<string> w;
		w += "dwadzieścia", "trzydzieści", "czterdzieści", "pięćdziesiąt", "sześćdziesiąt", "siedemdziesiąt", "osiemdziesiąt", "dziewięćdziesiąt";
		int ten = (num/10);
		int one = num%10;
		return 
			w.at(ten-2) 
			+ ((one!=0) ? (" "+SpellPl(one)) : (""));
	}

	if (num<=999) {
		int hundred = num / 100;
		string hundredStr="???";
		{
			vector<string> w;
			w += "???", "sto", "dwieście", "trzysta", "czterysta", "pięćset", "sześćset", "siedemset",	"osiemset", "dziewięćset";
			hundredStr = w.at(hundred);
		};

		int rest = num % 100;
		return 
			hundredStr
			+ ((rest!=0) ? (" "+SpellPl(rest)) : (""));
	}

	if (num<=99*999) {
		int thousand = num / 1000;
		string thousandStr="";
		if (thousand==1) thousandStr = "tysiąc";
		else if (thousand<=4) thousandStr = SpellPl(thousand) + " tysiące";
		else thousandStr = SpellPl(thousand) + " tysięcy";

		int rest = num % 1000;
		return 
			thousandStr
			+ ((rest!=0) ? (" "+SpellPl(rest)) : (""));
	}

	return "???";
}


void Test(int i) {
	std::cout << std::setw(5) << i << " is " << SpellEn(i) << std::endl;
	std::cout << std::setw(5) << i << " to " << SpellPl(i) << std::endl;
}

int main(int argc, const char** argv) {

	if (argc>=2) {
		using std::cout; using std::endl;

		float num=0;
		std::istringstream str(argv[1]);
		str>>num;
		
		int full = (int)num;
		int cent = (int)(0.1 + (num - full) * 100);

		cout<<full<<" € "<<cent<<" €/100" << ": "<<endl;

		cout << SpellEn(full) << " euro";
		if (cent!=0) cout << " and " << SpellEn(cent) << " eurocent";
		cout<<endl;
		

		cout << SpellPl(full) << " euro";
		if (cent!=0) {
			cout << " i " << SpellPl(cent) << " ";
			if (cent==1) cout << "eurocent";
			if (cent<=4) cout << "eurocenty";
			else cout << "eurocentów";
		}

		cout<<endl;
	}

	else {

	for (int i=-5; i<25; ++i) Test(i);

	for (int i=20; i<100; i+=10) {
		Test(i);
		Test(i+1);
		Test(i+9);
	}


	for (int i=100; i<1000; i+=100) {
		Test(i);
		Test(i+1);
		Test(i+11);
		Test(i+43);
	}

	for (int i=1000; i<20*1000; i+=1000) {
		Test(i);
		Test(i+1);
		Test(i+11);
		Test(i+43);
		Test(i+234);
		Test(i+354);
		Test(i+454);
		Test(i+654);
		Test(i+999);
	}

	}

}