U E D R , A S I H C RSS

Immediate Decodability/문보창

소감

2005/02/28 Accepted 0:00.189 440
단순히 조건에 나와있는데로 Decodablility를 파악해 주면 되는 문제다. 코드를 계속 압축해 나가다 보니 수시간이 갈수록 빨라졌고, 상위에 랭크될 수 있었다.

코드

~cpp 
// no644 - Immediate Decodability
#include <iostream>
#include <cstring>
using namespace std;

const int MAX = 10;

int main()
{
	char code[MAX][11];
	int i, j, k;
	int count = 1;
	int nCode, len;
	bool isDecodable;
	while (cin.peek() != EOF)
	{
		for (i=0; i<MAX; i++)
		{
			cin.getline(code[i], 11, '\n');
			if (code[i][0] == '9')
				break;
		} 

		nCode = i;
		for (i=0; i<nCode; i++)
		{
			for (j=0; j<nCode; j++)
			{
				if (i==j)
					continue;
				isDecodable = false;
				len = strlen(code[i]);
				for (k=0; k<len; k++)
				{
					if (code[i][k] != code[j][k])
					{
						isDecodable = true;
						break;
					}
				}
				if (isDecodable == false)
					break;
			}
			if (isDecodable == false)
				break;
		}
		cout << "Set " << count++;
		if (!isDecodable)
			cout << " is not immediately decodable\n";
		else
			cout << " is immediately decodable\n";
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:27
Processing time 0.0086 sec