如有条件在检查位置
if conditions in checking location
我正在解决这个问题,但我被另外两个if条件卡住了。我不确定如何检查从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 availablen" << endl;
}
// confused on this case
if(c == c[0]( ){
cout << "5 moves only availablen" << endl;
}
// and this case
if(c ==){
cout << "all 8 moves are availablen" << 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 availablen" << endl;
}
最后一种情况是:
else{
cout << "all 8 moves only availablen" << endl;
}
其他情况都已处理完毕
相关文章:
- 编译时检查以确保结构中的任何位置都没有填充
- 在 c++ 中检查 if 条件中的向量位置范围
- 检查向量是否在某个位置未初始化
- 如何检查指针是否指向正确对齐的内存位置
- 如何检查鼠标单击位置是必需的应用程序
- 迭代矢量如何检查我的位置
- 如何检查以前是否C++找到过最大值位置
- C++健全性检查失败:几个变量/内存位置被更改为垃圾,即使我从未访问过它们
- 检查阵列位置在C++中是否为空的 CPU 高效方法
- qt检查文件中是否存在文件,如果它没有提示用户输入其位置,则将文件复制到程序工作目录
- 如何检查应用程序在OS X下的位置
- Win32 C++-检查窗口位置X/PositionY和宽度/高度是否已更改
- libvlc 检查媒体位置是否有效
- 使用 clang llvm 检查变量在任意源位置的作用域是否具有范围
- LPCSTR-如何检查第一个位置是否为空格" "
- 检查阵列位置是否为空/空
- 检查数组的X位置是否为char
- 如何使用GetPixel()来检查不同的位置
- 在PDCurses/NCurses中检查当前/给定位置的字符
- 检查阵列位置