Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Plus Minus
- import Foundation
- // number of elements
- let n = Int(readLine()!)!
- // read array and map the elements to integer
- let arr = readLine()!.components(separatedBy: " ").map{ Int($0)! }
- var posi = 0
- var nega = 0
- var zero = 0
- for i in 0..<n {
- if arr[i] > 0 {posi += 1}
- else if arr[i] == 0 {zero += 1}
- else {nega += 1}
- }
- let posifraction = Double(posi)/Double(n)
- let negafraction = Double(nega)/Double(n)
- let zerofraction = Double(zero)/Double(n)
- //자리수 지정 어떻게하나
- print((posifraction)E-5)
- print((negafraction)E-5)
- print((zerofraction)E-5)
- ---
- * Staircase
- import Foundation
- // read the integer n
- let n = Int(readLine()!)!
- // print the staircase
- for i in 1...n{
- if i==n{print("",terminator:"")}
- else {for j in 1...n-i {print(" ",terminator:"")}}
- for j in 1...i {print("#",terminator:"")}
- print()
- }
- ---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement