我正在解决这个问题,如果遇到其他问题,我将被困在另外两个问题上。我不确定如何从b到g或2-7进行检查。我也对如何检查所有8个位置是否可用感到困惑。在使用if和for循环迭代或检查代码时,我总是感到困惑。这是我到目前为止的内容:问题:http : //codeforces.com/problemset/problem/710/a
到目前为止的代码:
#include <iostream>
#include <string>
using namespace std;
int main(){
string c;
cin >> c;
if(c == "a8" || c == "h8" || c == "a1" || c == h1){
cout << "3 moves only available\n" << endl;
}
// confused on this case
if(c == c[0]( ){
cout << "5 moves only available\n" << endl;
}
// and this case
if(c ==){
cout << "all 8 moves are available\n" << endl;
}
}
首先,h1
因为它是字符串文字,所以应该以逗号分隔,应该看起来像这样"h1"
。
其次,只有5个动作的情况是沿着棋盘的一侧(但不是角)。因此,您只需要检查文件(列)是否为'a'
或'h'
或等级(行)是否为'1'
或'8'
。使用else if
缩写来编码,这样在拐角处就不会输出两次。
因此,您的第二种情况如下所示:
else if (c[0] == 'a' || c[0] == 'h' || c[1] == '1' || c[1] == '8){
cout << "5 moves only available\n" << endl;
}
最后一种情况是:
else{
cout << "all 8 moves only available\n" << endl;
}
因为其他所有案件都已处理
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句