0
0

ループメニュー問題を解いていく1

Posted at

python

for i in range(10):
    print(i+1)

PHPは仕方ないけど行数多くなってしまうな

<?php
    for ($i=1; $i<=10; $i++){
        print($i . "\n");
    }
?>

じゃ次

python

for i in range(int(input())):
    print(i+1)

PHPだと、pythonのように直接入れ込む、ということはできないようです。
つまり下の$i<=$Nの部分を$i<=fgets(STDIN)のようにはできないようです。
何故か調べてますがなかなかそれらしきものは見つからず。
仕方ないのでこのままにします。汗

<?php
    $N = trim(fgets(STDIN));
    for ($i=1; $i<=$N; $i++){
        print($i . "\n");
    }
?>

じゃ次

python

for i in list(map(int,input().split())):
    print(i)

PHP
思った通り、直接やる方法はここでもあまりうまくいかないですね

<?php
    $A = explode(" ",fgets(STDIN));
    foreach ($A as $i){
        print($i . "\n");
    };
?>

じゃ次

python

N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    print(A[i])

PHP

<?php
    $N = trim(fgets(STDIN));
    $A = explode(" ",fgets(STDIN));
    for ($i=0; $i<=$N; $i++){
        print($A[$i]."\n");
    }
?>
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0