Rating 800 总目录
题目链接入口
题目描述
检查某国国旗是否满足ISO标准,ISO标准,每一行颜色是一样的,相邻行的颜色不能相同。用数字0~9代表颜色,国旗为n×m的矩形。
输入
第一行输入n,m代表国旗行列,紧接着再输入国旗的颜色。
输出
如果国旗符合ISO标准,则打印“YES”,否则打印“NO”。
案例
输入案例
3 3
000
111
222
输出案例
YES
输入案例
3 3
000
000
111
输出案例
NO
输入案例
3 3
000
111
002
输出案例
NO
题解:
满足ISO标准有两个要求:
- 每一行的内容相同
- 相邻的行内容不相同
#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; }
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
#define N 110
char a[N][N];
signed main()
{
IOS;
int n = read();
int m = read();
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
int flag = 1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (a[i][0] != a[i][j] || a[i][0] == a[i + 1][0])
{
flag = 0;
break;
}
}
if (!flag)
break;
}
if (flag)
printf("YES\n");
else
printf("NO\n");
return 0;
}