Back to General discussions forum
let tringle = input().split();
for(i=0; i<tringle.length; i++) {
output(tringle[i]);
}
input = 578 293 628
698 1079 1182
987 1606 3744
981 1559 632
...
Hello,
Task #9 When I iterate over input data by for loop this method gives only the first triple digits.
I still don't understand what you mean. What output are you getting? If you submit your answer + code (not copying to forum), I will be able to see the code, even if the answer is wrong.
If you're trying to process the data given by Problem #9, read on.
The first line of data should tell you how many iterations to loop for. What I would do is read in the first line as n
, then loop (i=0; i<n; i++){ ... }
.
You will need to call input()
inside of your loop body to read each subsequent line.
let triangle = input().split(' ');
let S = 0;
for(i=0; i<triangle.length; i++) {
S += + tringle[i] / 2;
}
let sum = S * ( S - triangle[0]) * ( S - triangle[1]) * ( S - triangle[2]);
if(sum <= 0) {
sum = 0;
} else {
sum = 1;
}
output(sum);
Stas, Hi!
Every input()
allows you to assign next line of input into the variable.
So your input()
should be inside the loop (but you have it outside).
E.g.
let numLines = input() * 1; // I use *1 to make number from string, I'm poor at javascript
for (let i = 0; i < numLines; i++) {
let nextTriangle = input().split(' ');
// ... do something
}
Thank you guys for your help something becomes clearer