Advertisement
Imran2544

Roman Digititis (AC)

Jan 31st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int i[110],v[110],x[110],l[110],c[110];
  4. string Ar_to_Ro(int q)
  5. {
  6.     string ans="";
  7.     map<int,string>wq;
  8.     map<int,string>::reverse_iterator g;
  9.     wq[1000]="m";
  10.     wq[900]="cm";
  11.     wq[500]="d";
  12.     wq[400]="cd";
  13.     wq[100]="c";
  14.     wq[90]="xc";
  15.     wq[50]="l";
  16.     wq[40]="xl";
  17.     wq[10]="x";
  18.     wq[9]="ix";
  19.     wq[5]="v";
  20.     wq[4]="iv";
  21.     wq[1]="i";
  22.     for(g=wq.rbegin(); g!=wq.rend(); g++)
  23.     {
  24.         while(q>=g->first)
  25.         {
  26.             ans+=(g->second);
  27.             q-=g->first;
  28.         }
  29.     }
  30.     return ans;
  31. }
  32. void cnt()
  33. {
  34.     string s;
  35.     for(int j=1; j<=100; j++)
  36.     {
  37.         i[j]=i[j-1];
  38.         v[j]=v[j-1];
  39.         x[j]=x[j-1];
  40.         l[j]=l[j-1];
  41.         c[j]=c[j-1];
  42.         s=Ar_to_Ro(j);
  43.         //cout<<s<<endl;
  44.         for(int k=0; s[k]; k++)
  45.         {
  46.             if(s[k]=='i')i[j]++;
  47.             else if(s[k]=='v')v[j]++;
  48.             else if(s[k]=='x')x[j]++;
  49.             else if(s[k]=='l')l[j]++;
  50.             else if(s[k]=='c')c[j]++;
  51.         }
  52.     }
  53. }
  54. int main()
  55. {
  56.     cnt();
  57.     int n;
  58.     while(cin>>n && n)
  59.     {
  60.         printf("%d: %d i, %d v, %d x, %d l, %d c\n",n,i[n],v[n],x[n],l[n],c[n]);
  61.     }
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement