看着满眼的for 跪了,留作纪念吧
/* ID: forthee1 PROG: clocks LANG: C++ */ #include <fstream> using namespace std; int m1[3][3] = {{3,3,0},{3,3,0},{0,0,0}}; int m2[3][3] = {{3,3,3},{0,0,0},{0,0,0}}; int m3[3][3] = {{0,3,3},{0,3,3},{0,0,0}}; int m4[3][3] = {{3,0,0},{3,0,0},{3,0,0}}; int m5[3][3] = {{0,3,0},{3,3,3},{0,3,0}}; int m6[3][3] = {{0,0,3},{0,0,3},{0,0,3}}; int m7[3][3] = {{0,0,0},{3,3,0},{3,3,0}}; int m8[3][3] = {{0,0,0},{0,0,0},{3,3,3}}; int m9[3][3] = {{0,0,0},{0,3,3},{0,3,3}}; int main() { ifstream inFile("clocks.in"); ofstream outFile("clocks.out"); int i,j,c1,c2,c3,c4,c5,c6,c7,c8,c9,ori[3][3],flag,temp; for(i=0;i<3;i++) for(j=0;j<3;j++) { inFile >> ori[i][j]; } for(c9=0;c9<=3;c9++) for(c8=0;c8<=3;c8++) for(c7=0;c7<=3;c7++) for(c6=0;c6<=3;c6++) for(c5=0;c5<=3;c5++) for(c4=0;c4<=3;c4++) for(c3=0;c3<=3;c3++) for(c2=0;c2<=3;c2++) for(c1=0;c1<=3;c1++) { flag = 1; for(i=0;i<3;i++) for(j=0;j<3;j++) if((ori[i][j]+c1*m1[i][j]+c2*m2[i][j]+c3*m3[i][j]+c4*m4[i][j]+c5*m5[i][j]+c6*m6[i][j]+c7*m7[i][j]+c8*m8[i][j]+c9*m9[i][j])%12!=0) {flag =0; break;} if(i==3 && j==3 && flag==1) { for(temp=0;temp<c1;temp++) if(temp<c1-1) outFile << 1 <<' '; else outFile << 1; if (c1>0&&(c2>0 ||c3>0 ||c4>0 ||c5>0 ||c6>0 ||c7>0 ||c8>0||c9>0)) outFile <<' '; for(temp=0;temp<c2;temp++) if(temp<c2-1) outFile << 2 <<' '; else outFile << 2; if(c2>0&&(c3>0 ||c4>0 ||c5>0 ||c6>0 ||c7>0 ||c8>0||c9>0)) outFile <<' '; for(temp=0;temp<c3;temp++) if(temp<c3-1) outFile << 3 <<' '; else outFile << 3; if(c3>0&&(c4>0 ||c5>0 ||c6>0 ||c7>0 ||c8>0||c9>0)) outFile <<' '; for(temp=0;temp<c4;temp++) if(temp<c4-1) outFile << 4 <<' '; else outFile << 4; if(c4>0&&(c5>0 ||c6>0 ||c7>0 ||c8>0||c9>0)) outFile <<' '; for(temp=0;temp<c5;temp++) if(temp<c5-1) outFile << 5 <<' '; else outFile << 5; if(c5>0&&(c6>0 ||c7>0 ||c8>0||c9>0)) outFile <<' '; for(temp=0;temp<c6;temp++) if(temp<c6-1) outFile << 6 <<' '; else outFile << 6; if(c6>0&&(c7>0 ||c8>0||c9>0)) outFile <<' '; for(temp=0;temp<c7;temp++) if(temp<c7-1) outFile << 7 <<' '; else outFile << 7; if(c7>0&&(c8>0||c9>0)) outFile <<' '; for(temp=0;temp<c8;temp++) if(temp<c8-1) outFile << 8 <<' '; else outFile << 8; if(c8>0&&c9>0) outFile <<' '; for(temp=0;temp<c9;temp++) if(temp<c9-1) outFile << 9 <<' '; else outFile << 9; outFile<<endl; return 0; } } return 0; }
TASK: clocks
LANG: C++
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.011 secs, 3180 KB]
Test 2: TEST OK [0.000 secs, 3180 KB]
Test 3: TEST OK [0.011 secs, 3180 KB]
Test 4: TEST OK [0.011 secs, 3180 KB]
Test 5: TEST OK [0.000 secs, 3180 KB]
Test 6: TEST OK [0.011 secs, 3180 KB]
Test 7: TEST OK [0.022 secs, 3180 KB]
Test 8: TEST OK [0.022 secs, 3180 KB]
Test 9: TEST OK [0.022 secs, 3180 KB]
All tests OK.
原文链接: https://www.cnblogs.com/bugeili/archive/2011/12/12/2285251.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
![section 1.4.2 The clocks](https://www.ccppcoding.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/38414
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!