标签:style blog color os io ar for div sp
差点画蛇添足了,呵呵:
/* ID: qq104801 LANG: C++ TASK: preface */ #include <iostream> #include <fstream> #include <string> #include <vector> #include <cstdio> using namespace std; int n; char c[4][2]={‘I‘,‘V‘,‘X‘,‘L‘,‘C‘,‘D‘,‘M‘}; int cc[4][2]={0}; void calc(int n) { int w=0; while(n!=0) { switch(n%10) { case 1:cc[w][0]++;break; case 2:cc[w][0]+=2;break; case 3:cc[w][0]+=3;break; case 4:cc[w][0]++;cc[w][1]++;break; case 5:cc[w][1]++;break; case 6:cc[w][1]++;cc[w][0]++;break; case 7:cc[w][1]++;cc[w][0]+=2;break; case 8:cc[w][1]++;cc[w][0]+=3;break; case 9:cc[w+1][0]++;cc[w][0]++;break; //case 0:cc[w+1][0]++;break; } n/=10; w++; } } void test() { freopen("preface.in","r",stdin); freopen("preface.out","w",stdout); cin>>n; while(n)calc(n--); int i,j; for(i=0;i<4;i++) for(j=0;j<2;j++) if(cc[i][j])cout<<c[i][j]<<" "<<cc[i][j]<<endl; } int main () { test(); return 0; }
/* ID: qq104801 LANG: C++ TASK: preface */ #include <iostream> #include <fstream> #include <string> #include <vector> #include <cstdio> using namespace std; int n; char c[4][2]={‘I‘,‘V‘,‘X‘,‘L‘,‘C‘,‘D‘,‘M‘}; int cc[4][2]={0}; void calc(int n) { int w=0; while(n!=0) { switch(n%10) { case 1:cc[w][0]++;break; case 2:cc[w][0]+=2;break; case 3:cc[w][0]+=3;break; case 4:cc[w][0]++;cc[w][1]++;break; case 5:cc[w][1]++;break; case 6:cc[w][1]++;cc[w][0]++;break; case 7:cc[w][1]++;cc[w][0]+=2;break; case 8:cc[w][1]++;cc[w][0]+=3;break; case 9:cc[w+1][0]++;cc[w][0]++;break; //case 0:cc[w+1][0]++;break; } n/=10; w++; } } void test() { freopen("preface.in","r",stdin); freopen("preface.out","w",stdout); cin>>n; while(n)calc(n--); int i,j; for(i=0;i<4;i++) for(j=0;j<2;j++) if(cc[i][j])cout<<c[i][j]<<" "<<cc[i][j]<<endl; } int main () { test(); return 0; }
test data:
USER: cn tom [qq104801] TASK: preface LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.005 secs, 3372 KB] Test 2: TEST OK [0.003 secs, 3372 KB] Test 3: TEST OK [0.003 secs, 3372 KB] Test 4: TEST OK [0.003 secs, 3372 KB] Test 5: TEST OK [0.003 secs, 3372 KB] Test 6: TEST OK [0.003 secs, 3372 KB] Test 7: TEST OK [0.005 secs, 3372 KB] Test 8: TEST OK [0.003 secs, 3372 KB] All tests OK. Your program (‘preface‘) produced all correct answers! This is your submission #2 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!
标签:style blog color os io ar for div sp
原文地址:http://www.cnblogs.com/dpblue/p/3955339.html