USACO1.2.2 - transform

来源:互联网 发布:java微信公众号开发pdf 编辑:程序博客网 时间:2024/06/06 20:26

复习累了就做做题目,今天这个程序让我很好的感受到了把一个程序写成不同的功能模块的好处。(虽然我这个小程序都不能称为什么模块化)。这个题目我错了好多次,但是还好我每种变换都对应了一个函数,所以找起错误了很方便,而且总体的思路也比较的清晰。usaco的题目都可以在nocow上面找到翻译,所以我就不再赘述题目的意思了。

题目链接:http://cerberus.delos.com:790/usacoprob2?a=FjdZ7dkHoSz&S=transform

代码:

/*  ID:sunexio2  PROG:transform  LANG:C++ */#include <iostream>#include <fstream>using namespace std;ifstream fin ("transform.in");ofstream fout("transform.out");char p[15][15];char q[15][15];int  n;int check1(){for(int i = 0; i < n; ++i)for(int j = 0; j < n; ++j)if(p[n - j - 1][i] != q[i][j])return 0;return 1;}int check2(){for(int i = 0; i < n; ++i){for(int j = 0; j < n; ++j){if(p[n - i - 1][n - j - 1] != q[i][j])return 0;}}return 1;}int check3(){for(int i = 0; i < n; ++i){for(int j = 0; j < n; ++j){if(p[j][n - i - 1] != q[i][j])return 0;}}return 1;}int check4(){for(int i = 0; i < n; ++i){for(int j = 0; j < n; ++j){if(p[i][n - j - 1] != q[i][j])return 0;}}return 1;}int check5(){char h[15][15];bool flag = 1;    for(int i = 0; i < n; ++i)for(int j = 0; j < n; ++j)h[i][j] = p[i][n - j - 1];for(int i = 0; i < n; ++i)for(int j = 0; j < n; ++j){if(p[i][j] != q[i][j])flag = 0;    p[i][j] = h[i][j];}    if(check1()){fout << 5 << endl;return 1;}if(check2()){fout << 5 << endl;return 1;}if(check3()){fout << 5 << endl;return 1;}if(flag){fout << 6 << endl;return 1;}return 0;}/*int check6(){for(int i = 0; i < n; ++i)for(int j = 0; j < n; ++j)if(p[i][j] != q[i][j])return 0;return 1;}*/int main(){while(fin >> n){for(int i = 0; i < n; ++i)fin >> p[i];for(int i = 0; i < n; ++i)fin >> q[i];if(check1())fout << 1 << endl;else if(check2())fout << 2 << endl;else if(check3())fout << 3 << endl;else if(check4())fout << 4 << endl;else if(check5()) ;//fout << 5 << endl;/*else if(check6())fout << 6 << endl;*/elsefout << 7 << endl;}return 0;}


0 0