USACO Section 2.1: Preface Numbering

看网上的,太琐碎

 1 /*

 2 ID: yingzho2

 3 PROG: preface

 4 LANG: C++

 5  */

 6 #include <iostream>

 7 #include <fstream>

 8 #include <string>

 9 #include <map>

10 #include <vector>

11 #include <set>

12 #include <algorithm>

13 #include <queue>

14 #include <cmath>

15 #include <list>

16 #include <cstring>

17 #include <cstdlib>

18 #include <limits>

19 #include <stack>

20 

21 using namespace std;

22 

23 ofstream fout ("preface.out");

24 ifstream fin ("preface.in");

25 const char ch[8]={'4','I','V','X','L','C','D','M'};

26 const int a[4][10]={

27     0,0,0,0,0,0,0,0,0,0,

28     0,1,2,3,1,0,1,2,3,1,

29     0,0,0,0,1,1,1,1,1,0,

30     0,0,0,0,0,0,0,0,0,1};

31 int ans[13];

32 int n,i,j,t;

33 

34 int main(){

35     fin >> n;

36     for (int k=1;k<=n;++k){

37         t=k;

38         for (i=0;i<=3;++i){

39             for (j=1;j<=3;++j)

40                 ans[i*2+j]+=a[j][t%10];

41             t=t/10;

42             if (t==0) break;

43         }

44     }

45     for (i=1;i<=7;++i)

46         if (ans[i]!=0) fout << ch[i] << " " << ans[i] << endl;

47     return 0;

48 }

 

你可能感兴趣的:(number)