题目理解难度远大于编程难度,逻辑很简单,copy了一下别人的代码,然后修改通过的。
大部分人没通过的关键在于:对于9行 or 9列的表,无论你插入几都是错的!
#include <iostream> using namespace std; int main() { int r, c, r1, c1, r2, c2, ri, ci, rt, ct; while (cin >> r >> c >> r1 >> c1 >> r2 >> c2 >> ri >> ci >> rt >> ct) { if (r>9 || c>9) cout << "-1" << endl; else cout << "0" << endl; if (r1 >= 0 && r1<r && c1 >= 0 && c1<c && r2 >= 0 && r2<r && c2 >= 0 && c2<c) cout << "0" << endl; else cout << "-1" << endl; if (ri >= 0 && ri<r && r<9) cout << "0" << endl; else cout << "-1" << endl; if (ci >= 0 && ci<c && c<9) cout << "0" << endl; else cout << "-1" << endl; if (rt >= 0 && rt<r && ct >= 0 && ct<c) cout << "0" << endl; else cout << "-1" << endl; } return 0; }