0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ループメニュー1をやっていく3

Posted at

Python

N = int(input())
A = list(map(int, input().split()))
# 下記でもOK
# A = [int(i) for i in input().split()]
sum = 0
for i in A:
    sum += i
    
print(sum)

PHP

<?php
    $N = fgets(STDIN);
    $A = explode(" ",fgets(STDIN));
    $sum = 0;
    for ($i=0; $i<=count($A); $i++){
           $sum += $A[$i];
    }
    print($sum);
?>

各言語の挙動の違いに手こずられますね汗

Python

N,A,B = map(int,input().split())
arr = [int(i) for i in input().split()]
sum = 0
for i in range(A-1,B):
    sum += arr[i]
    
print(sum)

PHP

<?php
    list($N,$A,$B) = explode(" ",fgets(STDIN));
    $arr = explode(" ",fgets(STDIN));
    $sum = 0;
    
    for ($i=$A; $i<=$B; $i++){
          $sum += $arr[$i-1];
    }
    print($sum);
?>
0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?