"STDIN 정수 배열(세로) 입력 받기"의 두 판 사이의 차이

22번째 줄: 22번째 줄:
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#include <stdlib.h>


struct numTag {
struct numTag {

2018년 8월 14일 (화) 23:53 판

1 개요

STDIN 정수 배열(세로) 입력 받기
건수가 제시된 경우
4
19
3
12
28
건수가 제시되지 않은 경우
19
3
12
28

2 C

건수가 제시되지 않은 경우
#include <stdio.h>
#include <ctype.h>

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

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

    do {
        c = getc(stdin);
        if(isdigit(c)) {
            sNum.num[sNum.size++] = c - '0';
        }
    } while (c != EOF);

    return 0;
}

3 Bash

건수가 제시된 경우
read n
NUM=
for i in `seq 1 $n`
do
    read s
    NUM="$NUM $s"
done
echo $NUM
# 19 3 12 28

4 Perl

건수가 제시된 경우
$n=<>;
@nums=();
push @nums, $b=<> for (1..$n);
print @nums;
# 19
# 3
# 12
# 28
건수가 제시되지 않은 경우
print <>;
# 19
# 3
# 12
# 28

5 PHP

건수가 제시된 경우
<?php
$n = intval(fgets(STDIN));
$nums = [];
for($i=0; $i<$n; $i++) $nums[] = intval(fgets(STDIN));
for($i=0; $i<$n; $i++) echo $nums[$i] . ' ';
# 19 3 12 28

6 Python

건수가 제시되지 않은 경우
from sys import stdin
nums = list(map(int,stdin))
print(nums)
# [19, 3, 12, 28]

7 같이 보기

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