Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- map<int,string>DecimalToRoman;
- string s;
- void DtoR(int value)
- {
- DecimalToRoman[100] = "C"; DecimalToRoman[90] = "XC";
- DecimalToRoman[50] = "L"; DecimalToRoman[40] = "XL";
- DecimalToRoman[10] = "X"; DecimalToRoman[9] = "IX";
- DecimalToRoman[5] = "V"; DecimalToRoman[4] = "IV";
- DecimalToRoman[1] = "I";
- map<int,string>::reverse_iterator it;
- s = "";
- for(it = DecimalToRoman.rbegin();it!=DecimalToRoman.rend();it++)
- {
- while(value>=it->first)
- {
- s+=(string) it->second;
- value-=it->first;
- }
- }
- }
- int main()
- {
- int len,i,j,value,R,I,V,X,L,C;
- while(scanf("%d",&value)&&value)
- {
- I=V=X=L=C=0;
- for(i=1;i<=value;i++)
- {
- DtoR(i);
- len = s.length();
- for(j=0;j<len;j++)
- {
- if(s[j]=='I')
- {
- I++;
- }
- else if(s[j]=='V')
- {
- V++;
- }
- else if(s[j]=='X')
- {
- X++;
- }
- else if(s[j]=='L')
- {
- L++;
- }
- else if(s[j]=='C')
- {
- C++;
- }
- }
- }
- printf("%d: %d i, %d v, %d x, %d l, %d c\n",value,I,V,X,L,C);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment