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
|
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;
void breakOut(string str, int &i, int &j, int &k);
int main()
{
std::string saRoom[20] = {
"1,10,19", "0,2,6", "1,3,13", "2,4,8",
"3,5,15", "4,6,12", "1,5,7", "6,8,18",
"3,7,9", "8,10,17", "0,9,11", "10,12,14",
"5,11,13", "2,12,14", "11,13,15", "4,14,16",
"15,17,19", "9,16,18", "7,17,19", "0,16,18"
};
int a, b, c;
for (int i=0; i<20; i++)
{
breakOut(saRoom[i], a, b, c);
cout << setw(10) << saRoom[i]
<< setw(4) << a << setw(4) << b << setw(4) << c << endl;
}
return 0;
}
void breakOut(string str, int &i, int &j, int &k)
{
// replace all commas with spaces
size_t pos = 0;
while ((pos = str.find(',',pos)) != string::npos)
str[pos] = ' ';
istringstream buffer(str);
buffer >> i >> j >> k;
}
|
1,10,19 1 10 19
0,2,6 0 2 6
1,3,13 1 3 13
2,4,8 2 4 8
3,5,15 3 5 15
4,6,12 4 6 12
1,5,7 1 5 7
6,8,18 6 8 18
3,7,9 3 7 9
8,10,17 8 10 17
0,9,11 0 9 11
10,12,14 10 12 14
5,11,13 5 11 13
2,12,14 2 12 14
11,13,15 11 13 15
4,14,16 4 14 16
15,17,19 15 17 19
9,16,18 9 16 18
7,17,19 7 17 19
0,16,18 0 16 18 |