-
Notifications
You must be signed in to change notification settings - Fork 1
/
cost.cpp
61 lines (49 loc) · 1 KB
/
cost.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
// Maze Cost
// Jeff Ruhl
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int get_cost( char );
int main( int argc, char *argv[] ) {
ifstream in("cost.in");
if ( in ) {
ofstream out("cost.out");
string line;
getline( in, line );
int set_count = atoi( line.c_str() );
for ( int i = 0; i < set_count; i++ ) {
int cost = 0;
int row_count, col_count;
in >> row_count; in >> col_count;
// consume rest of line
getline( in, line );
for ( int row = 0; row < row_count; row++ ) {
getline( in, line );
for ( int col = 0; col < col_count; col++ ) {
cost += get_cost( line[col] );
}
}
out << cost << endl;
}
out.close();
in.close();
}
else {
cout << "File 'cost.in' not found" << endl;
}
return 0;
}
int get_cost( char segment ) {
switch ( segment ) {
case 'X':
return 50;
case '-':
return 10;
case '+':
return 500;
default:
return 0;
}
}