// UVa 154 - Recycling
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main() {
int id[256];
id['r'] = 0;
id['o'] = 1;
id['y'] = 2;
id['g'] = 3;
id['b'] = 4;
string l;
while (getline(cin, l) && (l[0] != '#')) {
int n = 0;
string raw[100];
while (l[0] != 'e') {
raw[n++] = l;
getline(cin, l);
}
char city[100][5];
for (int i = 0; i < n; i++) {
int s = raw[i].find('/');
while (s >= 0 && s < raw[i].length()) {
city[i][id[raw[i][s - 1]]] = raw[i][s + 1];
raw[i] = raw[i].substr(s + 1);
s = raw[i].find('/');
}
}
int ss = 501;
int sol = 0;
for (int i = 0; i < n; i++) {
int c = 0;
for (int j = 0; j < n; j++) {
for (int k = 0; k < 5; k++)
if (city[i][k] != city[j][k])
c++;
}
if (c < ss) {
ss = c;
sol = i;
}
}
cout << sol + 1 << endl;
}
return 0;
}
Saturday, June 6, 2015
UVa 154 - Recycling
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment