"S10 Day 0: Weighted Mean"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 3개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;<nowiki>Day 0: Weighted Mean</nowiki>
;<nowiki>Day 0: Weighted Mean</nowiki>
;<nowiki>0일차:</nowiki> [[가중 평균]]
* https://www.hackerrank.com/challenges/s10-weighted-mean/problem
* https://www.hackerrank.com/challenges/s10-weighted-mean/problem


8번째 줄: 9번째 줄:


==같이 보기==
==같이 보기==
* [[해커랭크 10 Days of Statistics]]
* [[가중산술평균]]
* [[가중산술평균]]


==Python==
==Python==
<source lang='python'>
<syntaxhighlight lang='python'>
N = int(input())
N = int(input())
X = list(map(int, input().split()))
X = list(map(int, input().split()))
19번째 줄: 19번째 줄:
print(round((sum_X/sum(W)),1))
print(round((sum_X/sum(W)),1))
# 32.0
# 32.0
</source>
</syntaxhighlight>


==R==
==R==
<source lang='r'>
<syntaxhighlight lang='r'>
a <- scan("stdin")
a <- scan("stdin")
n <- a[1]
n <- a[1]
28번째 줄: 28번째 줄:
w <- a[n+1:n+1]
w <- a[n+1:n+1]
cat(sprintf("%.1f", weighted.mean(x,w) ))
cat(sprintf("%.1f", weighted.mean(x,w) ))
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
a <- scan(file="stdin")
a <- scan(file="stdin")
n <- a[1]
n <- a[1]
35번째 줄: 35번째 줄:
w <- a[n+1:n+1]
w <- a[n+1:n+1]
cat(sprintf("%.1f", weighted.mean(x,w) ))
cat(sprintf("%.1f", weighted.mean(x,w) ))
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
a <- scan("stdin")
a <- scan("stdin")
n <- a[1]
n <- a[1]
42번째 줄: 42번째 줄:
w <- a[(n+2):(2*n+1)]
w <- a[(n+2):(2*n+1)]
cat(sprintf("%.1f", weighted.mean(x,w) ))
cat(sprintf("%.1f", weighted.mean(x,w) ))
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
a <- scan("stdin")
a <- scan("stdin")
n <- a[1]
n <- a[1]
49번째 줄: 49번째 줄:
w <- a[(n+2):(2*n+1)]
w <- a[(n+2):(2*n+1)]
cat( format(sum(x*w)/sum(w),nsmall=1) )
cat( format(sum(x*w)/sum(w),nsmall=1) )
</source>
</syntaxhighlight>
<source lang='r'>
<syntaxhighlight lang='r'>
lines <- readLines(file('stdin', open='r'))
lines <- readLines(file('stdin', open='r'))
x <- as.numeric(unlist(strsplit(lines[2],split=" ")))
x <- as.numeric(unlist(strsplit(lines[2],split=" ")))
w <- as.numeric(unlist(strsplit(lines[3],split=" ")))
w <- as.numeric(unlist(strsplit(lines[3],split=" ")))
cat( format(sum(x*w)/sum(w),nsmall=1) )
cat( format(sum(x*w)/sum(w),nsmall=1) )
</source>
</syntaxhighlight>


[[분류: 10 Days of Statistics]]
[[분류: 10 Days of Statistics]]

2021년 7월 31일 (토) 10:35 기준 최신판

1 개요[ | ]

Day 0: Weighted Mean
0일차: 가중 평균
해커랭크 10 Days of Statistics
문제 C C++ C# Go Java node.js Perl PHP Python R Ruby
0-1 Day e
S10 Day 0: Mean, Median, and Mode
S10 Day 0: Weighted Mean
S10 Day 1: Quartiles
S10 Day 1: Interquartile Range
S10 Day 1: Standard Deviation

2 같이 보기[ | ]

3 Python[ | ]

N = int(input())
X = list(map(int, input().split()))
W = list(map(int, input().split()))
sum_X = sum([a*b for a,b in zip(X,W)])
print(round((sum_X/sum(W)),1))
# 32.0

4 R[ | ]

a <- scan("stdin")
n <- a[1]
x <- a[1:n+1]
w <- a[n+1:n+1]
cat(sprintf("%.1f", weighted.mean(x,w) ))
a <- scan(file="stdin")
n <- a[1]
x <- a[1:n+1]
w <- a[n+1:n+1]
cat(sprintf("%.1f", weighted.mean(x,w) ))
a <- scan("stdin")
n <- a[1]
x <- a[2:(n+1)]
w <- a[(n+2):(2*n+1)]
cat(sprintf("%.1f", weighted.mean(x,w) ))
a <- scan("stdin")
n <- a[1]
x <- a[2:(n+1)]
w <- a[(n+2):(2*n+1)]
cat( format(sum(x*w)/sum(w),nsmall=1) )
lines <- readLines(file('stdin', open='r'))
x <- as.numeric(unlist(strsplit(lines[2],split=" ")))
w <- as.numeric(unlist(strsplit(lines[3],split=" ")))
cat( format(sum(x*w)/sum(w),nsmall=1) )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}