준코딩

[Swift] 백준 25304번 문제 영수증 본문

알고리즘/Swift 백준 문제풀이

[Swift] 백준 25304번 문제 영수증

Ljunhyeob - App Dev 2023. 1. 5. 14:07

https://www.acmicpc.net/problem/25304

 

25304번: 영수증

준원이는 저번 주에 살면서 처음으로 코스트코를 가 봤다. 정말 멋졌다. 그런데, 몇 개 담지도 않았는데 수상하게 높은 금액이 나오는 것이다! 준원이는 영수증을 보면서 정확하게 계산된 것

www.acmicpc.net

 

https://github.com/Ljunhyeob/baekjoon25304

 

GitHub - Ljunhyeob/baekjoon25304: 백준 - 25304

백준 - 25304. Contribute to Ljunhyeob/baekjoon25304 development by creating an account on GitHub.

github.com

//
//  main.swift
//  baekjoon25304
//
//  Created by 이준협 on 2023/01/04.
//

import Foundation

let total = readLine()!
let count = readLine()!

let totalmoney = Int(total)!
let countNum = Int(count)!

var sum = 0

var arr : [Int] = []

for i in 0..<countNum{
    let line = readLine()!
    let lineArr = line.components(separatedBy: " ")
    let a = Int(lineArr[0])!
    let b = Int(lineArr[1])!
    arr.append(a*b)
}

for i in 0..<arr.count{
    sum = sum + arr[i]
}

if totalmoney == sum {
    print("Yes")
}else {
    print("No")
}
Comments