USACO chapter2 section 2 Preface Numbering

USACO chapter2 section 2 Preface Numbering

USER: tian tianbing [tbbd4261]
TASK: preface
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.022 secs, 3012 KB]
Test 2: TEST OK [0.000 secs, 3012 KB]
Test 3: TEST OK [0.022 secs, 3012 KB]
Test 4: TEST OK [0.011 secs, 3012 KB]
Test 5: TEST OK [0.000 secs, 3012 KB]
Test 6: TEST OK [0.011 secs, 3012 KB]
Test 7: TEST OK [0.011 secs, 3012 KB]
Test 8: TEST OK [0.011 secs, 3012 KB]
All tests OK.

Your program ('preface') produced all correct answers! This is your submission #9 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 -------
1
------- test 2 -------
20
------- test 3 -------
100
------- test 4 -------
500
------- test 5 -------
1000
------- test 6 -------
2974
------- test 7 -------
3213
------- test 8 -------
3499
Keep up the good work!
 Thanks for your submission!


之所以提交了9次,就是因为代码中有system("pause"); 没编译错误,没提示 搞死了!!
不过还好做出来了,浪费了很多时间
/*
ID:tbbd4261
PROG:preface
LANG:C++
*/

#include
< fstream >
using   namespace  std;

ifstream  fin(
" preface.in " );
ofstream  fout(
" preface.out " );
 
  
//         {"","I","II","III","IV","V","VI","VII","VIII","IX"},
  
//         {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},
  
//         {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"},
  
//         {"","M","MM","MMM"}

int  cg[ 7 ][ 10 ] =  {{ 0 , 1 , 2 , 3 , 1 , 0 , 1 , 2 , 3 , 1 },   // I
                { 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 },   // V
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 }, // X
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // L
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // C
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // D
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } // M
                };
int  cs[ 7 ][ 10 ] =  {
                {
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // I
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // V
                { 0 , 1 , 2 , 3 , 1 , 0 , 1 , 2 , 3 , 1 }, // X
                { 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 }, // L
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 }, // C
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // D
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } // M
               };
 
int  cb[ 7 ][ 10 ] = {
                {
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // I
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // V
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // X
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, // L
                { 0 , 1 , 2 , 3 , 1 , 0 , 1 , 2 , 3 , 1 }, // C
                { 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 }, // D
                { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 } // M
                };
 
int  cq[ 7 ][ 4 ] = {
                {
0 , 0 , 0 , 0 }, // I
                { 0 , 0 , 0 , 0 }, // V
                { 0 , 0 , 0 , 0 }, // X
                { 0 , 0 , 0 , 0 }, // L
                { 0 , 0 , 0 , 0 }, // C
                { 0 , 0 , 0 , 0 }, // D
                { 0 , 1 , 2 , 3 } // M
     };

int  main()
{
    
int  n,cnt0 = 0 ,cnt1 = 0 ,cnt2 = 0 ,cnt3 = 0 ,cnt4 = 0 ,cnt5 = 0 ,cnt6 = 0 ;
    fin
>> n;    
    
for ( int  i = 1 ; i <= n; i ++ )
    {
            cnt0
+= cg[ 0 ][i % 10 ];
            cnt1
+= cg[ 1 ][i % 10 ];
            cnt2
+= cg[ 2 ][i % 10 ] + cs[ 2 ][(i / 10 ) % 10 ];
            cnt3
+= cs[ 3 ][(i / 10 ) % 10 ];
            cnt4
+= cs[ 4 ][(i / 10 ) % 10 ] + cb[ 4 ][(i / 100 ) % 10 ];
            cnt5
+= cb[ 5 ][(i / 100 ) % 10 ];
            cnt6
+= cb[ 6 ][(i / 100 ) % 10 +  cq[ 6 ][(i / 1000 ) % 10 ]; 
    }
    
if (cnt0)fout << " " << cnt0 << endl;
    
if (cnt1)fout << " " << cnt1 << endl;
    
if (cnt2)fout << " " << cnt2 << endl;
    
if (cnt3)fout << " " << cnt3 << endl;
    
if (cnt4)fout << " " << cnt4 << endl;
    
if (cnt5)fout << " " << cnt5 << endl;
    
if (cnt6)fout << " " << cnt6 << endl;
    
// system("pause");  
     return   0 ;
}

你可能感兴趣的:(USACO chapter2 section 2 Preface Numbering)