1027. Colors in Mars (20)

考察查询表以及求余分位

#include<iostream>
#include<vector>

char g_CharTable[13] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'};

void OutPutIntVector(const std::vector<int>& a)
{
	int size = (int)a.size();
	for(int i = 0; i < size; ++i)
	{
		printf("%c", g_CharTable[a[i]]);
	}
	printf("\n");
}
void Convert2MarsColor(int r, int g, int b, std::vector<int>& color)
{
	color.assign(6, 0);
	color[1] = r%13;
	color[0] = r/13;
	color[3] = g%13;
	color[2] = g/13;
	color[5] = b%13;
	color[4] = b/13;
}
int main()
{
	int r, g, b;
	while(scanf("%d%d%d", &r, &g, &b) != EOF)
	{
		std::vector<int> color;
		Convert2MarsColor(r, g, b, color);
		printf("#");
		OutPutIntVector(color);
	}
	return 0;
}


 

你可能感兴趣的:(pat,ZJU)