zoukankan      html  css  js  c++  java
  • [解题报告]344 Roman Digititis

     Roman Digititis 

    Many persons are familiar with the Roman numerals for relatively small numbers. The symbols ``i", ``v", ``x", ``l", and ``c" represent the decimal values 1, 5, 10, 50, and 100 respectively. To represent other values, these symbols, and multiples where necessary, are concatenated, with the smaller-valued symbols written further to the right. For example, the number 3 is represented as ``iii", and the value 73 is represented as ``lxxiii". The exceptions to this rule occur for numbers having units values of 4 or 9, and for tens values of 40 or 90. For these cases, the Roman numeral representations are ``iv" (4), ``ix" (9), ``xl" (40), and ``xc" (90). So the Roman numeral representations for 24, 39, 44, 49, and 94 are ``xxiv", ``xxxix", ``xliv", ``xlix", and ``xciv", respectively.

    The preface of many books has pages numbered with Roman numerals, starting with ``i" for the first page of the preface, and continuing in sequence. Assume books with pages having 100 or fewer pages of preface. How many ``i", ``v", ``x", ``l", and ``c" characters are required to number the pages in the preface? For example, in a five page preface we�ll use the Roman numerals ``i", ``ii", ``iii", ``iv", and ``v", meaning we need 7 ``i" characters and 2 ``v" characters.

    Input

    The input will consist of a sequence of integers in the range 1 to 100, terminated by a zero. For each such integer, except the final zero, determine the number of different types of characters needed to number the prefix pages with Roman numerals.

    Output

    For each integer in the input, write one line containing the input integer and the number of characters of each type required. The examples shown below illustrate an acceptable format.

    Sample Input

    1
    2
    20
    99
    0

    Sample Output

    1: 1 i, 0 v, 0 x, 0 l, 0 c
    2: 3 i, 0 v, 0 x, 0 l, 0 c
    20: 28 i, 10 v, 14 x, 0 l, 0 c
    99: 140 i, 50 v, 150 x, 50 l, 10 c




    题目不难,手打好累。。。。。


    #include <stdio.h>
    int num_i(int n)
    {
        int a=n%5;
        if(a==4) return 1;
        else return a;
    }
    int num_v(int n)
     {
        n%=10;
        if(n>=4&&n<=8) return 1;
        else return 0;
    }
    int num_x(int n)
     {
        n%=50;
        if (n<=8) return 0;
            else if(n>=9 && n<=18) return 1;
            else if(n>=19 && n<=28) return 2;
            else if(n>=29 && n<=38) return 3;
            else if(n==39) return 4;
            else if(n>=40 && n<=48) return 1;
            else return 2;
    }
    int num_l(int n)
     {
        if(n>=40 && n<=89) return 1;
            else return 0;
        }
    
    int num_c(int n)
    {
        if(n>=90) return 1;
            else return 0;
        }
    int main()
    {
        int n;
        int a;
        while (scanf("%d", &n)!=EOF)
        {
            int i=0,v=0,x=0,l=0,c=0;
            if(n==0) return 0;
            for (a=1;a<=n; a++)
            {
                i+=num_i(a);
                v+=num_v(a);
                x+=num_x(a);
                l+=num_l(a);
                c+=num_c(a);
            }
            printf("%d: %d i, %d v, %d x, %d l, %d c\n",n,i,v,x,l,c);
        }
    }
  • 相关阅读:
    CSP 2020 提高组第一轮
    初赛胡扯
    Sublime安装SublimeServer插件开启本地服务器
    Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in XXX ode_modules@babelhelper-compilation-targetspackage.json
    Vue解决less-loader报错 TypeError: this.getOptions is not a function
    Vue-cli项目关闭eslint检查
    Typora添加主题
    Oracle存储过程中EXECUTE IMMEDIATE 执行结果是空时怎么继续执行
    存储过程--异常捕获
    git和github的基本使用(2)
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2932193.html
Copyright © 2011-2022 走看看