-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16.cpp
49 lines (40 loc) · 1.01 KB
/
16.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
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <regex>
#include <fstream>
using namespace std;
class Valve
{
public:
Valve(string &name, int rate, string& connects) {
}
private:
string name;
int rate;
vector<string> tunnels;
};
int main() {
ifstream file("16.exp2");
string line;
while (getline(file, line)) {
char name[3], tunnels[80];
int rate;
sscanf(line.c_str(), "Valve %s has flow rate=%d; tunnels lead to valves %[^\t\n]\n", name, &rate, tunnels);
cout << "Name: " << name << endl;
cout << "Rate: " << rate << endl;
cout << "Tunnels: ";
cout << tunnels << endl;
regex tunnel_g("([A-Z]{2})");
smatch matches;
string tunnels_str(tunnels);
if (regex_search(tunnels_str, matches, tunnel_g)) {
for (int i = 1; i <= matches.size(); i++) {
cout << matches[i] << " ";
}
}
cout << endl << endl;
}
return 0;
}