Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. * Plus Minus
  2. import Foundation
  3.  
  4. // number of elements
  5. let n = Int(readLine()!)!
  6.  
  7. // read array and map the elements to integer
  8. let arr = readLine()!.components(separatedBy: " ").map{ Int($0)! }
  9.  
  10. var posi = 0
  11. var nega = 0
  12. var zero = 0
  13.  
  14. for i in 0..<n {
  15. if arr[i] > 0 {posi += 1}
  16. else if arr[i] == 0 {zero += 1}
  17. else {nega += 1}
  18. }
  19.  
  20. let posifraction = Double(posi)/Double(n)
  21. let negafraction = Double(nega)/Double(n)
  22. let zerofraction = Double(zero)/Double(n)
  23. //자리수 지정 어떻게하나
  24.  
  25. print((posifraction)E-5)
  26. print((negafraction)E-5)
  27. print((zerofraction)E-5)
  28.  
  29. ---
  30.  
  31. * Staircase
  32. import Foundation
  33.  
  34. // read the integer n
  35. let n = Int(readLine()!)!
  36.  
  37. // print the staircase
  38.  
  39. for i in 1...n{
  40. if i==n{print("",terminator:"")}
  41. else {for j in 1...n-i {print(" ",terminator:"")}}
  42. for j in 1...i {print("#",terminator:"")}
  43. print()
  44. }
  45.  
  46. ---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement