Translate

Views

Monday, June 5, 2023

Solution UVA: 344 - Roman Digititis


Last Submissions
  Problem  VerdictLangTimeBestRankSubmit Time
 | discuss344 - Roman Digititis AcceptedC++110.0000.000289147 secs ago


Problem: Click on table to read

Suggest:
- Run from 1 to 100 trying to turn those numbers into roman numbers 
+ If the number is < 10 we manually do the number in the units row
+ If that number < 100 we calculate the number in the tens manually then + with the units row calculated above
+ If that number = 100 we just take the result of 99 and add 1 to c

Code:
#include<bits/stdc++.h>
using namespace std;

int n;
int a[10][5];
int b[10][5];
int c[101][5];
int res[101][5];

// 0 1 2 3 4
// i v x l c

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
   
    a[1][0]= 1;
    a[2][0]= 2;
    a[3][0]= 3;
    a[4][0]= 1; a[4][1]=1;
    a[5][1]= 1;
    a[6][0]= 1; a[6][1]=1;
    a[7][0]= 2; a[7][1]=1;
    a[8][0]= 3; a[8][1]=1;
    a[9][0]= 1; a[9][2]=1;
   
    b[1][2]= 1;
    b[2][2]= 2;
    b[3][2]= 3;
    b[4][3]= 1; b[4][2]=1;
    b[5][3]= 1;
    b[6][3]= 1; b[6][2]=1;
    b[7][3]= 1; b[7][2]=2;
    b[8][3]= 1; b[8][2]=3;
    b[9][4]= 1; b[9][2]=1;
   
    for(int i=1; i<=100; i++)
        if (i<=9){

            for(int j=0; j<5; j++)
                res[i][j] = res[i-1][j] + a[i][j];
        }
       
        else
        if (i<100){
           
            for(int j=0; j<5; j++)
                res[i][j] = res[i-1][j] + b[i/10][j] + a[i%10][j];
        }
       
        else{
            for(int j=0; j<5; j++)
                res[i][j] = res[i-1][j];
            res[i][4] = res[i-1][4] + 1;
        }
           
    while(cin >> n && n){
        cout<<n<<": "<<res[n][0]<<" i, "<<res[n][1]<<" v, "<<res[n][2]<<" x, "<<res[n][3]<<" l, "<<res[n][4]<<" c\n";
    }      
}  



No comments: