UVA – 10324 – Zeros And Ones

#include <stdio.h>
#define max(a, b) ((a > b) ? a : b)
#define min(a, b) ((a < b) ? a : b)
int n, a, b, t = 0, k, i;

int check(char s[1000005], int a, int b) {
	if (a == b) return 1;
	for (i = min(a, b); i < max(a, b); ++i)
		if (s[i] ^ s[i + 1])	return 0;
	return 1;
}

int main() {
	char s[1000005];
	while (scanf("%s\n%d", s, &n)==2) {
		printf("Case %d:\n", ++t);
		for (k = 0; k < n; ++k) {
			scanf("%d%d\n", &a, &b);
			printf("%s\n", check(s,a,b) ? "Yes": "No");
		}
	}
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: