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

1 개요[ | ]

STDIN 정수 배열(가로) 입력 받기
표준입력
19 3 12 28

2 Bash[ | ]

read n
echo $n
# 19 3 12 28
read n
for s in $n
do
    echo $s
done
#19
#3
#12
#28

3 C[ | ]

#include <stdio.h>

struct numTag {
    int num[256];
    int size;
};

int main()
{
    struct numTag sNum = {{0, } , 0};
    int a;

    do {
        scanf("%d", &sNum.num[sNum.size++]);
    } while (getc(stdin) != '\n');

    return 0;
}

4 C#[ | ]

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

5 Perl[ | ]

@nums = split / /, <>;

6 PHP[ | ]

$nums = explode(' ', rtrim(fgets(STDIN)));
$nums = array_map('intval', explode(' ', fgets(STDIN)));
$nums = array_map('intval', preg_split('/ /', trim(fgets(STDIN)), -1, PREG_SPLIT_NO_EMPTY));

7 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

8 Swift[ | ]

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

9 같이 보기[ | ]

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