<p>Seven different symbols represent Roman numerals with the following values:</p>

<table>
	<thead>
		<tr>
			<th>Symbol</th>
			<th>Value</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>I</td>
			<td>1</td>
		</tr>
		<tr>
			<td>V</td>
			<td>5</td>
		</tr>
		<tr>
			<td>X</td>
			<td>10</td>
		</tr>
		<tr>
			<td>L</td>
			<td>50</td>
		</tr>
		<tr>
			<td>C</td>
			<td>100</td>
		</tr>
		<tr>
			<td>D</td>
			<td>500</td>
		</tr>
		<tr>
			<td>M</td>
			<td>1000</td>
		</tr>
	</tbody>
</table>

<p>Roman numerals are formed by appending&nbsp;the conversions of&nbsp;decimal place values&nbsp;from highest to lowest. Converting a decimal place value into a Roman numeral has the following rules:</p>

<ul>
	<li>If the value does not start with 4 or&nbsp;9, select the symbol of the maximal value that can be subtracted from the input, append that symbol to the result, subtract its value, and convert the remainder to a Roman numeral.</li>
	<li>If the value starts with 4 or 9 use the&nbsp;<strong>subtractive form</strong>&nbsp;representing&nbsp;one symbol subtracted from the following symbol, for example,&nbsp;4 is 1 (<code>I</code>) less than 5 (<code>V</code>): <code>IV</code>&nbsp;and 9 is 1 (<code>I</code>) less than 10 (<code>X</code>): <code>IX</code>.&nbsp;Only the following subtractive forms are used: 4 (<code>IV</code>), 9 (<code>IX</code>),&nbsp;40 (<code>XL</code>), 90 (<code>XC</code>), 400 (<code>CD</code>) and 900 (<code>CM</code>).</li>
	<li>Only powers of 10 (<code>I</code>, <code>X</code>, <code>C</code>, <code>M</code>) can be appended consecutively at most 3 times to represent multiples of 10. You cannot append 5&nbsp;(<code>V</code>), 50 (<code>L</code>), or 500 (<code>D</code>) multiple times. If you need to append a symbol&nbsp;4 times&nbsp;use the <strong>subtractive form</strong>.</li>
</ul>

<p>Given an integer, convert it to a Roman numeral.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">num = 3749</span></p>

<p><strong>Output:</strong> <span class="example-io">&quot;MMMDCCXLIX&quot;</span></p>

<p><strong>Explanation:</strong></p>

<pre>
3000 = MMM as 1000 (M) + 1000 (M) + 1000 (M)
 700 = DCC as 500 (D) + 100 (C) + 100 (C)
  40 = XL as 10 (X) less of 50 (L)
   9 = IX as 1 (I) less of 10 (X)
Note: 49 is not 1 (I) less of 50 (L) because the conversion is based on decimal places
</pre>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">num = 58</span></p>

<p><strong>Output:</strong> <span class="example-io">&quot;LVIII&quot;</span></p>

<p><strong>Explanation:</strong></p>

<pre>
50 = L
 8 = VIII
</pre>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">num = 1994</span></p>

<p><strong>Output:</strong> <span class="example-io">&quot;MCMXCIV&quot;</span></p>

<p><strong>Explanation:</strong></p>

<pre>
1000 = M
 900 = CM
  90 = XC
   4 = IV
</pre>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= num &lt;= 3999</code></li>
</ul>

class Solution {
public:
    void speedUp() {
        std::ios_base::sync_with_stdio(0);
        std::cin.tie(0);
    }

    std::string Is(int _num) {
        std::string is = "";
        int no_is = 0;
        if (_num % 5 > 0 &&_num % 5 <= 3) {
            no_is = _num % 5;
        }
        for (; no_is != 0; --no_is) {
            is += "I";
        }
        return is;
    }
    std::string Vs(int _num) {
        std::string vs = "";
        int no_vs = 0;
        bool i = false;
        if (_num % 10 == 4) {
            no_vs = 1;
            i = true;
        }
        else if(_num % 10 >= 5 && _num % 10 <= 8) {
            no_vs = 1;
        }
        for (; no_vs != 0; --no_vs) {
            if (i) {
                vs += "I";
            }
            vs += "V";
        }
        return vs;
    }
    std::string Xs(int _num) {
        std::string xs = "";
        int no_xs = 0;
        bool i = false;
        if (_num % 10 == 9) {
            i = true;
        }
        if(_num % 50 <= 39 ) {
            no_xs = ((_num % 50) - (_num % 10)) / 10;
        }

        for (; no_xs != 0; --no_xs) {
            xs += "X";
        }
        if (i) {
            xs += "IX";
        }
        return xs;
    }
    std::string Ls(int _num) {
        if (_num % 100 >= 90) {
            return "";
        }
        std::string ls = "";
        int no_ls = 0;
        bool x = false;
        if (_num % 100 < 50 && (_num % 100) >= 40) {
            no_ls = 1;
            x = true;
        }
        else {
            no_ls = ((_num % 100) - (_num % 50)) / 50;
        }

        for (; no_ls != 0; --no_ls) {
            if (x) {
                ls += "X";
            }
            ls += "L";
        }
        return ls;
    }
    std::string Cs(int _num) {
        bool xc = false;
        if (_num % 100 >= 90) {
            xc = true;
        }

        std::string cs = "";
        int no_cs = ((_num % 500) - (_num % 100)) / 100;
        if (_num % 500 >= 400) {
            no_cs = 0;
        }
        for (; no_cs != 0; --no_cs) {
            cs += "C";
        }

        if (xc) {
            cs += "XC";
        }
        return cs;
    }

    std::string Ds(int _num) {
        if (_num % 1000 >= 900) {
            return "";
        }
        bool cd = false;
        std::string ds = "";
        int no_ds = ((_num % 1000) - (_num % 500)) / 500;
        if (_num % 1000 >= 400 && _num % 1000 < 500) {
            return "CD";
        }
        for (; no_ds != 0; --no_ds) {
            ds += "D";
        }
        return ds;
    }
    std::string Ms(int _num) {
        std::string ms = "";
        int no_ms = (_num - (_num % 1000)) / 1000;
        bool cm = (_num % 1000 >= 900 && no_ms != 0);
        if (_num % 1000 >= 900 && no_ms == 0) {
            ms += "CM";
        }
        for (; no_ms != 0; --no_ms) {
            ms += "M";
        }
        if (cm) {
            ms += "CM";
        }
        return ms;
    }
    std::string intToRoman(int num) {
        speedUp();
        return Ms(num) + Ds(num) + Cs(num) + Ls(num) + Xs(num) + Vs(num) + Is(num);
    }
};
10819