Rating 800 总目录
题目链接入口
题目描述
一个特工要破解密码,他有一个热感应器,可以知道具体按下了哪些密码,终端是一个方形数字键盘3 × 3,数字范围为1到9。现在需要排除错误的密码,现在他想检查工作人员输入的密码是否中央对称。这个事实可以帮助特工减少不同密码组合的数量。(说白了:判断是否中心对称)
输入
输入一个三行三列的矩阵。符号«X»表示已按下相应的按钮,«.»表示未按下。矩阵可能不包含«X»,也可能不包含«.»。
输出
如果密码与终端中央按钮对称,则打印“YES”,否则打印“NO”。
案例
输入案例
XX.
...
.XX
输出案例
YES
输入案例
X.X
X..
...
输出案例
NO
题解:矩阵——二维数组保存,只需要判断输入的矩阵 相对应的点 是否相同即可。
C++代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read(){int w = 1, s = 0;char ch = getchar();while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); }return s * w;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
signed main()
{
char a[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
cin >> a[i][j];
if (a[0][0] == a[2][2] && a[0][1] == a[2][1] && a[0][2] == a[2][0] && a[1][0] == a[1][2])
printf("YES\n");
else
printf("NO\n");
return 0;
}
Java代码:
import java.util.Scanner;
public class codeforces {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] a = new char[3];
char[] b = new char[3];
char[] c = new char[3];
String str1,str2,str3;
str1 = sc.nextLine();
str2 = sc.nextLine();
str3 = sc.nextLine();
for (int i = 0; i < str1.length(); i++)
a[i] = str1.charAt(i);
for (int i = 0; i < str2.length(); i++)
b[i] = str2.charAt(i);
for (int i = 0; i < str3.length(); i++)
c[i] = str3.charAt(i);
if (a[0] == c[2] && a[1] == c[1] && a[2] == c[0] && b[0] == b[2])
System.out.println("YES");
else
System.out.println("NO");
}
}