How can I read following stdin for Google Kickstart oder Jam code etc.:
4
1 9
91 99
451 460
501 1000
So the 4 in the first line has to be in a var (e.g. $a);
Then in every line after that:
the first param goes into an Array of $b[] e.g.
And the same with the second param. In $c[] e.g.
So the result should be:
lang: PHP
$a = "4";
$b = ["1", "91", "451", "501"];
$c = ["9", "99", "460", "1000"];
It doesn't matter if it's an integer or a string.
Thank you
My Answer:
To read input in Google Kickstart using PHP, you can use the following code snippet:
php
// Read the number of test cases
fscanf(STDIN, "%d\n", $a);
// Initialize arrays to store the input values
$b = [];
$c = [];
// Read the input values for each test case
for ($i = 0; $i < $a; $i++) {
fscanf(STDIN, "%d %d\n", $b[], $c[]);
}
// Print the input values
echo "a = $a\n";
echo "b = [" . implode(", ", $b) . "]\n";
echo "c = [" . implode(", ", $c) . "]\n";
?>
You can run this code in your local environment or on an online PHP compiler. Just copy and paste the code, provide the input as mentioned in your question, and the code will output the desired result.
Rate this post
3 of 5 based on 3997 votesComments