STDIN 정수 배열(가로) 입력 받기

Jmnote (토론 | 기여)님의 2018년 8월 11일 (토) 21:48 판 (→‎Python)

1 개요

STDIN 정수 배열(가로) 입력 받기
입력값 예시
19 3 12 28

2 C#

int[] a = Console.ReadLine().Split(' ').Select(x=>Convert.ToInt32(x)).ToArray();

3 Perl

@nums = split / /, <>;

4 PHP

$nums = explode(' ', rtrim(fgets(STDIN)));
$nums = array_map('intval', explode(' ', fgets(STDIN)));

5 Python

nums = list(map(int,input().split()))
print( nums )
# [19, 3, 12, 28]
nums = [int(e) for e in input().split()]
print( nums )
# [19, 3, 12, 28]
nums = [int(e) for e in input().split(' ')]
print( nums )
# [19, 3, 12, 28]
nums = input().split()
print( nums )
# ['19', '3', '12', '28']
nums = map(int,input().split())
print( nums )
# <map object at 0x7fd92c102908>
for num in nums:
    print( num, end=' ')
# 19 3 12 28

6 Swift

let nums = readLine()!.components(separatedBy: " ").map{ Int($0)! }

7 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}