// UVa 644 - Immediate Decodability #include <string> #include <iostream> #include <stdio.h> #include <vector> using namespace std; int main() { int t = 0; string code; while (cin >> code) { vector<string> codes; while (code[0] != '9') { codes.push_back(code); cin >> code; } bool invalid = false; for (int i = 0; i < codes.size(); i++) { for (int j = i + 1; j < codes.size(); j++) { int l = min(codes[i].length(), codes[j].length()) - 1; while (l >= 0 && codes[i][l] == codes[j][l]) l--; if (l < 0) { invalid = true; break; } } if (invalid) break; } t++; if (!invalid) printf("Set %d is immediately decodable\n", t); else printf("Set %d is not immediately decodable\n", t); } return 0; }
Thursday, June 11, 2015
UVa 644 - Immediate Decodability
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment