Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- var input float64
- fmt.Scanln(&input)
- var change = int(input * 100)
- var coinCount = 0
- if change >= 200 {
- coinCount += change / 200
- change %= 200
- }
- if change >= 100 {
- coinCount += change / 100
- change %= 100
- }
- if change >= 50 {
- coinCount += change / 50
- change %= 50
- }
- if change >= 20 {
- coinCount += change / 20
- change %= 20;
- }
- if change >= 10 {
- coinCount += change / 10
- change %= 10
- }
- if change >= 5 {
- coinCount += change / 5
- change %= 5
- }
- if change >= 2 {
- coinCount += change / 2
- change %= 2
- }
- if change == 1 {
- coinCount++
- change--
- }
- fmt.Println(coinCount)
- }
- ИЛИ:
- package main
- import "fmt"
- func main() {
- var input float64
- fmt.Scanln(&input)
- var change = int(input * 100)
- for coinCount := 0; ; coinCount++ {
- if change == 0 {
- fmt.Println(coinCount)
- break
- } else if change >= 200 {
- change -= 200
- } else if change >= 100 {
- change -= 100
- } else if change >= 50 {
- change -= 50
- } else if change >= 20 {
- change -= 20
- } else if change >= 10 {
- change -= 10
- } else if change >= 5 {
- change -= 5
- } else if change >= 2 {
- change -= 2
- } else {
- change--
- }
- }
- }
- РЕШЕНИЯ С МАСИВ:
- package main
- import "fmt"
- func main() {
- var input float64
- fmt.Scanln(&input)
- var change = int(input * 100)
- coins := []int{200, 100, 50, 20, 10, 5, 2, 1}
- var coinCount = 0
- for i := 0; i < len(coins); i++ {
- if change >= coins[i] {
- coinCount += change / coins[i]
- change %= coins[i]
- }
- }
- fmt.Println(coinCount)
- }
- ИЛИ:
- package main
- import "fmt"
- func main() {
- var input float64
- fmt.Scanln(&input)
- var change = int(input * 100)
- coins := []int{200, 100, 50, 20, 10, 5, 2, 1}
- var coinCount = 0
- for _, coin := range coins {
- if change >= coin {
- coinCount += change / coin
- change %= coin
- }
- }
- fmt.Println(coinCount)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement