Skip to content

Instantly share code, notes, and snippets.

@nsmaciej
Created February 22, 2014 18:59
Show Gist options
  • Save nsmaciej/9160111 to your computer and use it in GitHub Desktop.
Save nsmaciej/9160111 to your computer and use it in GitHub Desktop.
s2.c
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#define each(a, b) for (a = 0; a < b; ++a)
int a = 1;
char getValid(void) {
char a;
while (true) {
a = getchar();
if (a == '*' || a == '.') return a;
}
}
int tn;
void analyse(void) {
bool R[101][101];
int i, j, w, h;
scanf("%d %d", &h, &w);
each(i, h) {
each(j, w) {
R[i][j] = getValid() == '*';
}
}
bool ct;
int ss = 0;
// Width
each(i, h) {
ct = R[i][0];
ss = 0;
each(j, w) {
if (R[i][j] != ct) {
ss += 1;
ct = R[i][j];
}
}
if (ss > 2 || (ss == 2 && ct == true)) {//* * * / * *
printf("Room %d: NO\n", a++);
return;
}
}
// Height
each(j, w) {
ct = R[0][j];
ss = 0;
each(i, h) {
if (R[i][j] != ct) {
ss += 1;
ct = R[i][j];
}
}
if (ss > 2 || (ss == 2 && ct == true)) {//* * * / * *
printf("Room %d: NO\n", a++);
return;
}
}
printf("Room %d: YES\n", a++);
}
int main(void) {
int i;
scanf("%d", &tn);
each(i, tn) {
analyse();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment