알고리즘 공부/미분류

백준 2475 번 Kotlin ★

_우지 2021. 7. 3. 15:12

import java.util.*
import kotlin.math.*
fun main() = with(Scanner(System.`in`)) {
// 코틀린 제곱을 사용하려고 했는데 아직 어려워서 java 제곱을 썻다.
// Math.pow(doulbe, double)
var ans = (Math.pow(nextDouble(),2.0) + Math.pow(nextDouble(),2.0)
+ Math.pow(nextDouble(),2.0) + Math.pow(nextDouble(),2.0)
+ Math.pow(nextDouble(),2.0))%10
println(ans.toInt()) // 출력값이 double형 이라서 Int로 고쳐주었다.
}

 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import kotlin.math.pow
 
val br = BufferedReader(InputStreamReader(System.`in`))
 
fun main()=with(br){
    val bw = BufferedWriter(OutputStreamWriter(System.out))
    val list = readLine()!!.split(" ").map{it.toDouble()}
    var sum = 0.0
    for(i in list.indices){
        sum+=list[i].pow(2)
    }
    sum %= 10
    bw.write("${sum.toInt()}")
    bw.flush()
    bw.close()
}
 
 
 
 
 
 
 
 
cs