andy0130tw
12/17/2015 - 3:53 PM

advent of code

advent of code

#include<string>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int x[1000][1000];

int main() {
	string s1, s2;
	int x1, x2, y1, y2, ans = 0;
	enum { ON, OFF, TOGGLE } st;

	while (cin >> s1) {
		if (s1 == "toggle") {
			st = TOGGLE;
		} else if (s1 == "turn") {
			cin >> s2;
			if (s2 == "on") st = ON;
			else st = OFF;
		} else break;

		scanf("%d,%d", &x1, &y1);
		cin >> s1;
		scanf("%d,%d", &x2, &y2);

		for (int i = x1; i <= x2; i++) {
			for (int j = y1; j <= y2; j++) {
				if (st == ON) {
					x[i][j]++;
					ans++;
				} else if (st == OFF && x[i][j] > 0) {
					x[i][j]--;
					ans--;
				} else if (st == TOGGLE) {
					x[i][j] += 2;
					ans += 2;
				}
			}
		}
	}
	cout << "ans=" << ans << endl;
}
#include<string>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

bool x[1000][1000];

int main() {
	string s1, s2;
	int x1, x2, y1, y2, ans = 0;
	enum { ON, OFF, TOGGLE } st;

	while (cin >> s1) {
		if (s1 == "toggle") {
			st = TOGGLE;
		} else if (s1 == "turn") {
			cin >> s2;
			if (s2 == "on") st = ON;
			else st = OFF;
		} else break;

		scanf("%d,%d", &x1, &y1);
		cin >> s1;
		scanf("%d,%d", &x2, &y2);

		for (int i = x1; i <= x2; i++) {
			for (int j = y1; j <= y2; j++) {
				if (x[i][j] && st != ON) {
					x[i][j] = false;
					ans--;
				} else if (!x[i][j] && st != OFF) {
					x[i][j] = true;
					ans++;
				}
			}
		}
	}
	cout << "ans=" << ans << endl;
}
import re

def good(s):
	if (not re.search(r'(..).*?\1', s)): return False
	if (not re.search(r'(.).\1', s)): return False
	return True

i = 0

while 1:
	s = input()
	if good(s):
		i+=1
	print(i)
import re

def good(s):
	a = 0
	for c in s:
		if c in ['a', 'e', 'i', 'o', 'u']:
			a+=1
	if (a <= 2): return False
	if (not re.search(r'(.)\1', s)): return False
	for p in ['ab', 'cd', 'pq', 'xy']:
		if (s.find(p) >= 0):
			return False
	return True

i = 0

while 1:
	s = input()
	if good(s):
		i+=1
	print(i)
import md5

i = 0

while 1:
	x = md5.new("bgvyzdsv" + str(i))
	if (x.hexdigest()[0:6] == '000000'):
		break
	i+=1

print(i)
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	int a, b, c;
	int ans = 0;
	while(scanf("%dx%dx%d", &a, &b, &c) == 3) {
		int p = a*b*c;
		int g = min(a, min(b, c));
		int m = p/g/max(a,max(b,c));
		ans += p + 2 * (g+m);
		printf("ans = %d\n", ans);
	}
}
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	int a, b, c;
	int ans = 0;
	while(scanf("%dx%dx%d", &a, &b, &c) == 3) {
		ans += 2 * (a*b+b*c+c*a) + min(a, min(b, c));
		printf("ans = %d\n", ans);
	}
}
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	int a = 0, l = 0;
	char c;
	while (scanf("%c", &c) == 1) {
		if (c == '(') l++;
		else if (c == ')') l--;
		else break;
		a++;
		if (l == -1) printf("a=%d\n", a);
	}
}
// no code required actually... any text editor can accomplish this...

Advent of Code

My own code material

** DISCLAMER: No code quality guaranteed, they are merely material. **