-
Notifications
You must be signed in to change notification settings - Fork 34
/
10651.cpp
executable file
·74 lines (59 loc) · 1.25 KB
/
10651.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Problem: Pebble Solitaire UVa 10651
Programmer: Md. Mahmud Ahsan
Description: Brute Force
Compiled: Visual C++ 7.0
Date: 27-03-06
*/
#include <iostream>
#include <string>
using namespace std;
char data[20];
int min, k;
int pebbleCount(){
int temp = 0;
for (int i = 0; i < 12; ++i)
if (data[i] == 'o')
++temp;
return temp;
}
void pebble(){
if (pebbleCount() < min)
min = pebbleCount();
for (int i = 0; i < 10; ++i){
if (data[i] == '-' && data[i+1] == 'o' && data[i+2] == 'o'){
data[i] = 'o';
data[i+1] = '-';
data[i+2] = '-';
if (pebbleCount() < min)
min = pebbleCount();
pebble();
data[i] = '-';
data[i+1] = 'o';
data[i+2] = 'o';
}
else if (data[i] == 'o' && data[i+1] == 'o' && data[i+2] == '-'){
data[i] = '-';
data[i+1] = '-';
data[i+2] = 'o';
if (pebbleCount() < min)
min = pebbleCount();
pebble();
data[i] = 'o';
data[i+1] = 'o';
data[i+2] = '-';
}
}
}
int main(){
//freopen("input.txt", "r", stdin);
int n;
cin >> n;
cin.getline(data, sizeof(data));//eat newline
while (n--){
cin.getline(data, sizeof(data));
min = 12;
pebble();
cout << min << endl;
}
return 0;
}