CF16A Flag
CF16A Flag
題意翻譯
題目描述
根據一項新的ISO標準,每一個國家的國旗應該是一個n×m的格子場,其中每個格子最多有10種不同的顏色。並且國旗應該有條紋:旗幟的每一行應包含相同顏色的方塊,相鄰的行的顏色應該是不同的。Berland政府要求你找出他們的國旗是否符合新的ISO標準。
輸入格式:
輸入的第一行包含數n和m( ( 1<=n,m<=100 ),其中n為行數,m為列數。接下來
是對旗的描述:以下N行中的每一行包含m個字符。每個字符是0到9之間的數字,代表相應正方形的顏色。
輸出格式:
如果國旗符合標準就輸出YES,否則輸出NO。
題目描述
According to a new ISO standard, a flag of every country should have a chequered field n×mn×m , each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland‘s government asked you to find out whether their flag meets the new ISO standard.
輸入輸出格式
輸入格式:
The first line of the input contains numbers nn and mm ( 1<=n,m<=1001<=n,m<=100 ), nn — the amount of rows, mm — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following nn lines contain mmcharacters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
輸出格式:
Output YES, if the flag meets the new ISO standard, and NO otherwise.
輸入輸出樣例
輸入樣例#1: 復制3 3
000
111
222
輸出樣例#1: 復制
YES
輸入樣例#2: 復制
3 3
000
000
111
輸出樣例#2: 復制
NO
輸入樣例#3: 復制
3 3
000
111
002
輸出樣例#3: 復制
NO
未評測
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,m; int map[110][110]; int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ string s;cin>>s; for(int j=0;j<m;j++) map[i][j+1]=s[j]-‘0‘; } for(int i=1;i<=n;i++){ int now=map[i][1]; for(int j=2;j<=m;j++) if(map[i][j]!=now){ cout<<"NO"<<endl; return 0; } } int now=map[1][1]; for(int i=2;i<=n;i++){ if(map[i][1]==now){ cout<<"NO"<<endl; return 0; } now=map[i][1]; } cout<<"YES"<<endl; }
CF16A Flag