11 vector
<string
> candidates
;
14 void load_corpus(istream
&corpus
,ostream
&os
)
17 while (getline(corpus
,s
)) {
18 if (s
.empty() ||s
[0] == '%')
22 string::size_type p
= 0;
23 while ((p
= s
.find('{',p
)) != string::npos
) {
24 string::size_type p2
= s
.find('}',p
);
25 if (p2
== string::npos
)
30 string s2
= s
.substr(item
.pos
+1,item
.len
-2);
33 if (p
== string::npos
)
35 item
.candidates
.push_back(s2
.substr(0,p
));
37 while (!s2
.empty() && s2
[0] == ',')
40 items
.push_back(item
);
45 vector
<uint
> limits
,pos
;
46 int i
,n
= items
.size();
48 for (i
= 0;i
< n
;i
++)
49 limits
[i
] = items
[i
].candidates
.size();
52 while (cg
.step(pos
)) {
55 for (i
= 0;i
< n
;i
++) {
56 sentence
+= s
.substr(p
,items
[i
].pos
-p
);
57 p
= items
[i
].pos
+items
[i
].len
;
58 sentence
+= items
[i
].candidates
[pos
[i
]];
60 sentence
+= s
.substr(p
);
61 os
<< sentence
<< endl
;
67 int main(int argc
,char **argv
)
69 load_corpus(cin
,cout
);