language: C++ 4.7.2 (gcc-4.7.2)
date: 637 days 6 hours ago
link:
visibility: public
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
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
 
#include <iostream>
#include <string>
#include <vector>
 
using namespace boost::phoenix;
using namespace boost::spirit;
using namespace boost::spirit::qi;
using namespace boost::spirit::ascii;
using namespace boost::spirit::arg_names;
 
struct point
{
   int x,y,z;
};
 
std::vector<point> points(0);
 
void setx(int x) { points.push_back(point()); points[points.size()-1].x = x; }
void sety(int y) { points[points.size()-1].y = y; }
void setz(int z) { points[points.size()-1].z = z; }
 
typedef void (*setcallback)(int);
 
setcallback setcallbacks[] = {&setx, &sety, &setz};
 
int cindex = 0;
 
void cint(int i)
{ 
   setcallbacks[cindex](i); 
   cindex = (cindex + 1)%3;
}
template <typename Iterator>
bool parse_numbers(Iterator first, Iterator last)
{
    bool r = phrase_parse
    (
        first, 
        last,         
        *( '(' >> int_[&cint] >> ',' >> int_[&cint] >> ',' >> int_[&cint] >> ')' ), 
        space 
    );
 
    if (first != last) // fail if we did not get a full match
        return false;
    return r;
}
 
int main()
{
    std::string str;
    while (getline(std::cin, str))
    {           
        if (parse_numbers(str.begin(), str.end()))
            std::cout << "Succeeded : " << str << std::endl;
        else
            std::cout << "Failed : " << str << std::endl;
    }
    for(size_t i = 0 ; i < points.size() ; i++ )
    {
        std::cout << "[" 
                  << points[i].x << "," << points[i].y << "," << points[i].z 
                  << "]" << std::endl; 
    }
    return 0;
}
  • upload with new input
  • result: Success     time: 0s    memory: 2872 kB     returned value: 0

    (8,7,15)
    (0,0,1) (0,3,2) (0,6,3)
    (1,0,4) (1,1,5)
    Succeeded : (8,7,15)
    Succeeded : (0,0,1) (0,3,2) (0,6,3)
    Succeeded : (1,0,4) (1,1,5)
    [8,7,15]
    [0,0,1]
    [0,3,2]
    [0,6,3]
    [1,0,4]
    [1,1,5]