Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Cowculations

377.c

/* 377 - Cowculations */

#include <stdio.h>
#include <string.h>

int
str2num(char *s) {
	int i;
	int num = 0;

	for (i=0; i<strlen(s); i++) {
		num *= 4;
		if (s[i]=='U') {
			num++;
		} else if (s[i]=='C') {
			num += 2;
		} else if (s[i]=='D') {
			num += 3;
		}
	}
	return num;
}

int
main(void) {
	int i,j;
	int n;
	int n1,n2;
	char buf[1024];

	scanf("%d", &n);
	printf("COWCULATIONS OUTPUT\n");
	for (i=0; i<n; i++) {
		scanf(" %s", buf);
		n1 = str2num(buf);
#if DEBUG
		printf("n1=%d\n", n1);
#endif
		scanf(" %s", buf);
		n2 = str2num(buf);
#if DEBUG
		printf("n2=%d\n", n2);
#endif
		for (j=0; j<3; j++) {
			char c;
			scanf(" %c", &c);
			if (c=='A') {
				n2 += n1;
			} else if (c=='R') {
				n2 /= 4;
			} else if (c=='L') {
				n2 *= 4;
			}
#if DEBUG
			printf("  >> n2=%d\n", n2);
#endif
		}
		scanf(" %s", buf);
		n1 = str2num(buf);
		if (n1==n2) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}
	printf("END OF OUTPUT\n");
	return 0;
}