I would read the first number outside the loop, and set a variable based on whether that number is positive or negative. Then I'd have the loop read numbers, and based on the variable know whether to expect a positive or negative number. If it gets what it expects, invert the value in the variable, and repeat. In something pseudo-codeish, something on this general order:
read(number)
// if this number's negative, expect the next to be positive (and vice versa)
expect_positive = number < 0
for (;;) {
read(number)
bool positive = number >= 0
if (positive != expect_positive)
break;
expect_positive = !expect_positive;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…