<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ijd123's Weblog</title>
	<atom:link href="http://ijd123.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ijd123.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Tue, 19 Feb 2008 03:24:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ijd123.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ijd123's Weblog</title>
		<link>http://ijd123.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ijd123.wordpress.com/osd.xml" title="Ijd123&#039;s Weblog" />
	<atom:link rel='hub' href='http://ijd123.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Roman Numerals</title>
		<link>http://ijd123.wordpress.com/2008/02/19/roman-numerals/</link>
		<comments>http://ijd123.wordpress.com/2008/02/19/roman-numerals/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 03:07:58 +0000</pubDate>
		<dc:creator>ijd123</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ijd123.wordpress.com/?p=3</guid>
		<description><![CDATA[Download roman.zip Download roman.cpp<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ijd123.wordpress.com&amp;blog=2911553&amp;post=3&amp;subd=ijd123&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Download <a href="http://www.geocities.com/ian_dunbar/roman.zip">roman.zip</a></p>
<p>Download <a href="http://www.geocities.com/ian_dunbar/roman.cpp.txt">roman.cpp</a></p>
<p><pre class="brush: cpp;">
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;

//
// macro to give the size of an array
//
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))

//
// roman - convert a number to roman numerals
//
// value:	unsigned int	: the number to convert, range: 1..3999 inclusive
// return:	std::string		: string containing the roman numerals
//
std::string roman (unsigned int value)
{
    // The Romans didn't have a numeral for zero
    if (value == 0) throw std::out_of_range(&quot;roman: value == 0&quot;);

    // This function is specified to support value up to 3999 only
    if (value &gt; 3999) throw std::out_of_range(&quot;roman: value &gt; 3999&quot;);

    // string to conatain the roman numerals
    std::string romanized;

    // strings to contain the characters used for digits 1..9 for the current power of 10.
    std::string I, V, X;

    // the roman numerals for 1 and 5 in ascending order of powers of 10
    // last two elements are ? to avoid out of bounds exception when using M as 1
    const char numeraldata[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M', '?', '?'};
    // use the p, p+size constructor for the vector to safely handle the above data
    std::vector&lt;char&gt; numerals (numeraldata, numeraldata + ARRAY_SIZE(numeraldata));

    // an index into the above array
    unsigned int index = 0;

    // the maximum index into the numerals array
    // -2 because of zero based index + null at end of string
    const size_t maxindex = (sizeof(numerals)/sizeof(numerals[0])) - 2;

    // for each power of 10 (1, 10, 100, 1000, etc)
    for (unsigned int i = value; i &gt; 0; i /= 10)
    {
        // get the current representation for the I,V,X pattern
        I = numerals.at(index++);
        V = numerals.at(index++);
        X = numerals.at(index); // not index++ because current X is reused for the representation of I next time around

        // generate the 0..9 I,V,X roman numeral pattern for the current power of 10
        // and prepend it to the numerals already generated for lower powers of 10
        switch (i % 10) {
            case 0: // romans have no zero representation in their numerals.
                break;
            case 1: // I
                romanized = I + romanized;
                break;
            case 2: // II
                romanized = I + I + romanized;
                break;
            case 3: // III
                romanized = I + I + I + romanized;
                break;
            case 4: // IV
                romanized = I + V + romanized;
                break;
            case 5: // V
                romanized = V + romanized;
                break;
            case 6: // VI
                romanized = V + I + romanized;
                break;
            case 7: // VII
                romanized = V + I + I + romanized;
                break;
            case 8: // VIII
                romanized = V + I + I + I + romanized;
                break;
            case 9: // IX
                romanized = I + X + romanized;
                break;
            default:
                break;
        }
    }
    // return the full string of roman numerals
    return romanized;
}

//
// generate the result for the full range
// in the same output format as the reference file, so I can diff it.
//
int main(int argc, char* argv[])
{
    try {

        std::cout &lt;&lt; std::endl;
        for (int i = 1; i &lt;= 3999; ++i)
        {
            std::cout &lt;&lt; i &lt;&lt; '\t' &lt;&lt; roman (i) &lt;&lt; std::endl;
        }

    } catch (std::out_of_range &amp;e) {
        std::cerr &lt;&lt; &quot;Exception: &quot; &lt;&lt; e.what() &lt;&lt; std::endl;
        return EXIT_FAILURE;

    } catch (...) {
        std::cerr &lt;&lt; &quot;Exception: Unknown Exception&quot; &lt;&lt; std::endl;
    }

    return EXIT_SUCCESS;
}</pre></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ijd123.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ijd123.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ijd123.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ijd123.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ijd123.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ijd123.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ijd123.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ijd123.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ijd123.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ijd123.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ijd123.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ijd123.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ijd123.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ijd123.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ijd123.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ijd123.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ijd123.wordpress.com&amp;blog=2911553&amp;post=3&amp;subd=ijd123&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ijd123.wordpress.com/2008/02/19/roman-numerals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1aba73edd0c9e734a09b01b9c62fa09d?s=96&#38;d=identicon" medium="image">
			<media:title type="html">ijd123</media:title>
		</media:content>
	</item>
	</channel>
</rss>
