Volume 1 / 0173->0176

パソコン甲子園2008予選 解答

Problem 0173 : Haunted House

#include <iostream>
#include <string>

using namespace std;


int main(void)
{
	int am, pm;
	string className;

	for( int i=0; i<9; i++ ){
		cin >> className >> am >> pm;
		cout << className << " " << am+pm << " " << am*200+pm*300 << endl;
	}

	return 0;
}

Problem 0174 : Badminton

#include <iostream>

using namespace std;


int main(void)
{
	char ch;
	int a, b;
	while( cin.get(ch), ch != '0' ){
		cin.putback(ch);
		a = b = 0;
		cin.get(ch);
		while( cin.get(ch), ch != '\n' ){
			if( ch == 'A' )
				a++;
			if( ch == 'B' )
				b++;
		}

		if( a > b )
			a++;
		else
			b++;

		cout << a << " " << b << endl;

	}

	return 0;
}

Problem 0175 : A King in Hawaii

#include <iostream>
#include <deque>

using namespace std;


int main(void)
{
	int n, i;
	deque<int> result;

	while( cin >> n, n != -1 ){
		result.clear();
		while( n > 0 ){
			result.push_front(n%4);
			n /= 4;
		}

		for( i=0; i<result.size(); i++ )
			cout << result[i];
		if( result.size() == 0 )
			cout << 0;
		cout << endl;
	}

	return 0;
}

Problem 0176 : What Color?

#include <iostream>
#include <string>
#include <math.h>
#include <limits.h>

using namespace std;


int main(void)
{
	struct color_tag {
		string name;
		int r, g, b;
	} colors[8];
	colors[0].name = "black";
		colors[0].r = 0; colors[0].g = 0; colors[0].b = 0;
	colors[1].name = "blue";
		colors[1].r = 0; colors[1].g = 0; colors[1].b = 255;
	colors[2].name = "lime";
		colors[2].r = 0; colors[2].g = 255; colors[2].b = 0;
	colors[3].name = "aqua";
		colors[3].r = 0; colors[3].g = 255; colors[3].b = 255;
	colors[4].name = "red";
		colors[4].r = 255; colors[4].g = 0; colors[4].b = 0;
	colors[5].name = "fuchsia";
		colors[5].r = 255; colors[5].g = 0; colors[5].b = 255;
	colors[6].name = "yellow";
		colors[6].r = 255; colors[6].g = 255; colors[6].b = 0;
	colors[7].name = "white";
		colors[7].r = 255; colors[7].g = 255; colors[7].b = 255;

	char ch;
	int rgb[3], min_i, i, j;
	long d, min;

	while( cin.get(ch), ch != '0' ){
		rgb[0] = rgb[1] = rgb[2] = 0;
		for( i=0; i<3; i++ ){
			for( j=16; j>0; j-=15 ){
				cin.get(ch);
				if( 'a' <= ch && ch <= 'f' )
					ch = (ch-'a')+10;
				else
					ch -= '0';
				rgb[i] += j*ch;
			}
		}

		cin.get(ch);

		min = INT_MAX;
		for( i=0; i<8; i++ ){
			d = (rgb[0]-colors[i].r)*(rgb[0]-colors[i].r)
				+ (rgb[1]-colors[i].g)*(rgb[1]-colors[i].g)
				+ (rgb[2]-colors[i].b)*(rgb[2]-colors[i].b);
			if( d < min ){
				min = d; min_i = i;
			}
		}

		cout << colors[min_i].name << endl;

	}
}