int main() { }
gets more points than submitting
code that doesn't work.
while (!(std::cin.eof())) {std::getline(std::cin, ln); // whatever. }
.eof()
doesn't produce a useful value.
getline()
could fail.
.eof()
is telling you about the previous read, not the one that's
about to be made.
while (true) { std::getline(std::cin, ln); if (std::cin.eof()) break; // whatever }
Or, even simpler,
while (std::getline(std::cin, ln)) { // whatever }
if (std::cin.eof()) return; while (std::getline(std::cin, ln)) { if (std::cin.eof()) break; // whatever }
$ gdb tidytree (gdb) run < /dev/null Starting program: tidytree < /dev/null Accessing element 0 in an empty vector. Program received signal SIGABRT, Aborted. (gdb) up 4 #4 findRoot() at main.cc:27 27 int y = clist[0].vpoint[0].y; (gdb) print clist.size() 0 (gdb)
int main () { while (getline(cin, buf)) { stroke s1(buff); if ( s1.fig == CIRCLE ) clist.push_back(s1); } }
for (unsigned i = 0; i < stk.size(); i++) tvec.push_back(slope(stk[i], stk[i + 1]));
for (unsigned i = 0; i < stk.size() - 1; i++) tvec.push_back(slope(stk[i], stk[i + 1]));
What's wrong with this?
.size()
is unsigned.
((unsigned) 0) - 1 = 4294967295
(on a sparc).
for (unsigned x = 0; x < pts.size(); x += 2) point.first = pts[x]; point.second = pts[x + 1];
What's wrong with this?
tidytree < /dev/null
.
tidytree < tidytree
.
f | n | - | + | y | ||
1 | 2 | 1 | 0 | 0 | 7 | |
2 | 3 | 1 | 0 | 0 | 6 | |
3 | 3 | 6 | 0 | 0 | 1 | |
4 | 4 | 6 | 0 | 0 | 0 | |
5 | 7 | 3 | 0 | 0 | 0 | |
6 | 5 | 5 | 0 | 0 | 0 | |
7 | 4 | 6 | 0 | 0 | 0 | |
8 | 7 | 3 | 0 | 0 | 0 | |
9 | 7 | 2 | 0 | 0 | 1 | |
10 | 5 | 3 | 0 | 0 | 2 |
int main() { strokes = read_strokes(std::cin) classify_strokes(strokes) root = organize_strokes(strokes) tidy_tree(root) output_tree(std::cout, root) }
getline(cin, line)
.
while (iss >> pt) pts.push_back(pt)
istream& operator>>(istream& is, point& pt) return is >> pt.x >> pt.y
iss
?
std::istringstream iss(line);
int tidy_tree(root, left_x, y) if (root.is_leaf()) root->set_center(left_x + node_radius, y) return left_x + 2*node_radius right_x = tidy_tree(root.left, left_x, y + gap) right_x = tidy_tree(root.right, right_x, y + gap) root->set_center((left_x + right_x)/2, y) return right_x
100 | 200 | 300 | 400 | 500 | 600 | 700 | 1500 | |
---|---|---|---|---|---|---|---|---|
0 | 1 | |||||||
10 | ||||||||
20 | 1 | 1 | 1 | |||||
30 | 2 | |||||||
40 | 1 | |||||||
50 | 1 | |||||||
60 | 1 | |||||||
70 | 1 | |||||||
80 | 1 | 1 | ||||||
90 | 1 | |||||||
Totals | 1 | 2 | 4 | 3 | 0 | 1 | 1 | 1 |
100 | 200 | 300 | |
---|---|---|---|
0 | |||
10 | 1 | ||
20 | |||
30 | 1 | 1 | |
40 | 1 | 1 | |
50 | 2 | ||
60 | 2 | ||
70 | 1 | 2 | |
80 | 1 | ||
90 | |||
Totals | 7 | 4 | 2 |
total | pages per procedure | |||
---|---|---|---|---|
procs | 1 | 2 | 3 | 4 |
2 | 2 | |||
7 | 5 | 2 | ||
9 | 8 | 1 | ||
11 | 2 | 5 | 3 | 1 |
11 | 7 | 4 | ||
22 | 16 | 6 | ||
$ parsess < /dev/null Invalid Input $
$ tidytree < one-node Error Not enough edges. $
void calcAngleDiff() bool found = false int i=0, psize = pv.size() int idx1 = 0 for (i = 1; i < psize; i++) if (pv[0].x != pv[1].x) idx1 = i; break; adjdiff = 0.0; for (i = idx1 + 1; i < psize; i++) if ((pv[0].x > pv[idx1].x && pv[i].x > pv[0].x ) || (pv[0].x < pv[idx1].x && pv[i].x < pv[0].x )) found = true; adjdiff = dv[idx1] - dv[i]; break; for (i = 1; i < psize; i++) if (pv[0].y != pv[1].y) idx1 = i; break; enddiff = dv[psize] - dv[idx1];
void calcAngleDiff( ) int psize = pv.size() enddiff = dv[psize] - dv[idx1]
if (r_bstr[i] < 48 || r_bstr[i] > 57)
48? 57? What are these? Are you sure?
if (str1[loc] == 32) // 32 is ASCII char sp
Oh? Is everything ASCII?
char ch[200] while cin.getline(ch, 200, '\n') ... f(200) ...
Have you changed all proper values?
Have you left alone all other values?
This page last modified on 11 February 2003.