superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Section 2.2 - Preface Numbering

Posted on 2009-03-28 17:10 superman 阅读(88) 评论(0)  编辑 收藏 引用 所属分类: USACO
 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     freopen("preface.in""r", stdin);
 8     freopen("preface.out""w", stdout);
 9 
10     int n;
11     cin >> n;
12 
13     int I, V, X, L, C, D, M;
14     I = V = X = L = C = D = M = 0;
15 
16     while (n)
17     {
18         int c = n--;
19         while (c)
20         {
21             if (c >= 1000) { c -= 1000, M++     ; continue; }
22             if (c >= 900 ) { c -= 900 , C++, M++continue; }
23             if (c >= 500 ) { c -= 500 , D++     ; continue; }
24             if (c >= 400 ) { c -= 400 , C++, D++continue; }
25             if (c >= 100 ) { c -= 100 , C++     ; continue; }
26             if (c >= 90  ) { c -= 90  , X++, C++continue; }
27             if (c >= 50  ) { c -= 50  , L++     ; continue; }
28             if (c >= 40  ) { c -= 40  , X++, L++continue; }
29             if (c >= 10  ) { c -= 10  , X++     ; continue; }
30             if (c >= 9   ) { c -= 9   , I++, X++continue; }
31             if (c >= 5   ) { c -= 5   , V++     ; continue; }
32             if (c >= 4   ) { c -= 4   , I++, V++continue; }
33             if (c >= 1   ) { c -= 1   , I++     ; continue; }
34         }
35     }
36 
37     if (I) cout << 'I' << ' ' << I << endl;
38     if (V) cout << 'V' << ' ' << V << endl;
39     if (X) cout << 'X' << ' ' << X << endl;
40     if (L) cout << 'L' << ' ' << L << endl;
41     if (C) cout << 'C' << ' ' << C << endl;
42     if (D) cout << 'D' << ' ' << D << endl;
43     if (M) cout << 'M' << ' ' << M << endl;
44 
45     return 0;
46 }
47 

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理