Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- typedef unsigned long long int ull;
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef pair<int,int> pii;
- typedef vector< pii > vpii;
- typedef set<int> sti;
- #define pb push_back
- #define pob pop_back
- #define mp make_pair
- #define ff first
- #define ss second
- #define loop1(i,n) for(int i=1; i<=int(n); i++)
- #define loop(i,y) for(int i=0; i<int(y); i++)
- #define rloop(i,y) for(int i=int(y)-1; i>=0; i--)
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- #define cspf(i) printf("Case %d: ", i)
- /// Constants
- #define eps 1e-9
- #define PI acos(-1.0) // 3.1415926535897932
- int main()
- {
- //read();
- char x[1000];
- while(scanf("%s",x)!=EOF){
- if(x[0]>='A' && x[0]<='Z'){
- int ln=strlen(x);
- int total=0;
- rloop(i,ln){
- if(x[i]=='V')
- total+=5;
- else if(x[i]=='L')
- total+=50;
- else if(x[i]=='D')
- total+=500;
- else if(x[i]=='I'){
- if(x[i+1]=='V' || x[i+1]=='X')
- total-=1;
- else
- total+=1;
- }
- else if(x[i]=='X'){
- if(x[i+1]=='L' || x[i+1]=='C')
- total-=10;
- else
- total+=10;
- }
- else if(x[i]=='C'){
- if(x[i+1]=='D' || x[i+1]=='M')
- total-=100;
- else
- total+=100;
- }
- else if(x[i]=='M')
- total+=1000;
- }
- printf("%d\n",total);
- }
- else if(x[0]>='0' && x[0]<='9'){
- int ln=strlen(x);
- char y[100];
- int z=ln;
- int j=0;
- loop(i,ln){
- z--;
- int k=x[i]-48;
- if(z>=3){
- int w=z-3;
- w=pow(10,w);
- k*=w;
- while(k--){
- y[j]='M';
- j++;
- }
- }
- else if(z==2){
- if(k<=3){
- while(k--){
- y[j]='C';
- j++;
- }
- }
- else if(k==4){
- y[j]='C';
- j++;
- y[j]='D';
- j++;
- }
- else if(k==5){
- y[j]='D';
- j++;
- }
- else if(k<=8){
- y[j]='D';
- j++;
- k-=5;
- while(k--){
- y[j]='C';
- j++;
- }
- }
- else if(k==9){
- y[j]='C';
- j++;
- y[j]='M';
- j++;
- }
- }
- else if(z==1){
- if(k<=3){
- while(k--){
- y[j]='X';
- j++;
- }
- }
- else if(k==4){
- y[j]='X';
- j++;
- y[j]='L';
- j++;
- }
- else if(k==5){
- y[j]='L';
- j++;
- }
- else if(k<=8){
- y[j]='L';
- j++;
- k-=5;
- while(k--){
- y[j]='X';
- j++;
- }
- }
- else if(k==9){
- y[j]='X';
- j++;
- y[j]='C';
- j++;
- }
- }
- else if(z==0){
- if(k<=3){
- while(k--){
- y[j]='I';
- j++;
- }
- }
- else if(k==4){
- y[j]='I';
- j++;
- y[j]='V';
- j++;
- }
- else if(k==5){
- y[j]='V';
- j++;
- }
- else if(k<=8){
- y[j]='V';
- j++;
- k-=5;
- while(k--){
- y[j]='I';
- j++;
- }
- }
- else if(k==9){
- y[j]='I';
- j++;
- y[j]='X';
- j++;
- }
- }
- }
- loop(s,j){
- printf("%c",y[s]);
- }
- printf("\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement