dev/algorithm
BOJ / 4796๋ฒ / ์บ ํ [Go][Python3]
crscnt
2021. 3. 1. 21:00
๐ฉ๐ป๐ป ๋ฌธ์
4796๋ฒ: ์บ ํ
์ ๋ ฅ์ ์ฌ๋ฌ ๊ฐ์ ํ ์คํธ ์ผ์ด์ค๋ก ์ด๋ฃจ์ด์ ธ ์๋ค. ๊ฐ ํ ์คํธ ์ผ์ด์ค๋ ํ ์ค๋ก ์ด๋ฃจ์ด์ ธ ์๊ณ , L, P, V๋ฅผ ์์๋๋ก ํฌํจํ๊ณ ์๋ค. ๋ชจ๋ ์ ๋ ฅ ์ ์๋ int๋ฒ์์ด๋ค. ๋ง์ง๋ง ์ค์๋ 0์ด 3๊ฐ ์ฃผ์ด์ง๋ค.
www.acmicpc.net
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/4796
package main
import (
"bufio"
"fmt"
"math"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
for i := 1; ; i++ {
var l, p, v int
fmt.Fscanln(reader, &l, &p, &v)
if l == 0 && p == 0 && v == 0 {
break
}
fmt.Fprintf(writer, "Case %d: %d\n", i, (v/p)*l+int(math.Min(float64(v%p), float64(l))))
}
}
๐จ Python3
# https://www.acmicpc.net/problem/4796
import sys
if __name__ == "__main__":
i = 1
while True:
l, p, v = list(map(int, sys.stdin.readline().split()))
if l == 0 and p == 0 and v == 0:
break
print("Case {}: {}".format(i, (v//p)*l + min(v%p, l)))
i += 1
728x90