Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void Ar_to_Ro(int q)
- {
- map<int,string>wq;
- map<int,string>::reverse_iterator g;
- wq[1000]="M";
- wq[900]="CM";
- wq[500]="D";
- wq[400]="CD";
- wq[100]="C";
- wq[90]="XC";
- wq[50]="L";
- wq[40]="XL";
- wq[10]="X";
- wq[9]="IX";
- wq[5]="V";
- wq[4]="IV";
- wq[1]="I";
- for(g=wq.rbegin();g!=wq.rend();g++){
- while(q>=g->first){
- printf("%s",(g->second).c_str());
- q-=g->first;
- }
- }
- printf("\n");
- }
- void Ro_to_Ar(string q)
- {
- int g,nt=0;
- map<char,int>wq;
- wq['I']=1;
- wq['V']=5;
- wq['X']=10;
- wq['L']=50;
- wq['C']=100;
- wq['D']=500;
- wq['M']=1000;
- for(g=0;q[g];g++){
- if(q[g+1]&&wq[q[g]]<wq[q[g+1]]){
- nt+=wq[q[g+1]]-wq[q[g]];
- g++;
- }
- else nt+=wq[q[g]];
- }
- printf("%d\n",nt);
- }
- int main()
- {
- int w;
- string q;
- while(cin>>q){
- if(q[0]>=65&&q[0]<=90) Ro_to_Ar(q);
- else{
- w=stoi(q);
- Ar_to_Ro(w);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement