UVa 344 Roman digititis: Roman Numeral statistics

Source: Internet
Author: User
Tags time limit

344-roman Digititis

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=280

The

Many persons are familiar with the Roman is numerals for relatively small. The symbols ' i ', ' V ', ' x ', ' l ', and ' C ' represent the decimal values 1, 5, ten, and respectively. To represent other values, such as symbols, and multiples where necessary, are concatenated, with the smaller-valued Written further to the right. For example, the number 3 are represented as ' III ', and the ' value ' is represented as ' LXXIII '. The exceptions to this rule occur for numbers has units values of 4 or 9, and for tens values of or 90. For these cases, the Roman numeral representations are ' IV ' (4), ' IX ' (9), ' XL ' (+), and ' XC ' (90). So the Roman numeral representations for all, are ' xxiv ', ' xxxix ', ' xliv ', ' XLIX ', and ' xciv ', resp ectively.

The preface of many books has pages numbered with Roman numerals, starting and ' I ' for the ' the ' the ' the ' preface, D continuing in sequence. Assume books with pages have or fewer pages of preface. How many ' I ', ' V ', ' x ', ' l ', and ' C ' characters are required to number of 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 would consist of a sequence of integers in the range 1 to-terminated by a zero. For each such integer, except the final zero, determine the number of different types of characters needed to number the P Refix pages with Roman numerals.

Output

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45519.htm

For each integer in the input, write one line containing the "input integer" and "number of characters of each type Requi Red. 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, V, x, 0 L, 0 C
99:140 I, V, X, L, M C

Think of a lot of options, and finally feel the switch to 9 single digits and 9 10-digit processing the most convenient.

Complete code:

/*0.016s*/#include <bits/stdc++.h> using namespace std;  
    
int i[105], v[105], x[105], l[105], c[105];  
    int main () {int n, t; for (t = 1; t <= ++t) {switch (T/10) {Case 1: ++x[t]  
                ;  
            Break  
                Case 2:x[t] + + 2;  
            Break  
                Case 3:x[t] + + 3;  
            Break  
                Case 4: ++x[t], ++l[t];  
            Break  
                Case 5: ++l[t];  
            Break  
                Case 6: ++x[t], ++l[t];  
            Break  
                Case 7:x[t] + + 2, ++l[t];  
            Break  
                Case 8:x[t] + + 3, ++l[t];  
            Break  
        Case 9: ++x[t], ++c[t];  
 Switch (t%) {Case 1:               ++I[T];  
            Break  
                Case 2:i[t] + + 2;  
            Break  
                Case 3:i[t] + + 3;  
            Break  
                Case 4: ++i[t], ++v[t];  
            Break  
                Case 5: ++v[t];  
            Break  
                Case 6: ++i[t], ++v[t];  
            Break  
                Case 7:i[t] + + 2, ++v[t];  
            Break  
                Case 8:i[t] + + 3, ++v[t];  
            Break  
        Case 9: ++x[t], ++i[t];  
        if (t = =) ++c[t];  
    I[t] + = I[t-1], v[t] + = V[t-1], x[t] + = X[t-1], l[t] + = L[t-1], c[t] + = c[t-1]; while (scanf ("%d", &n), N) printf ("%d:%d I,%d V,%d X,%d L,%d c\n", N, I[n), V[n], x[n], l[n], C  
    [n]);  
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.