-
Notifications
You must be signed in to change notification settings - Fork 0
/
1073.swift
48 lines (38 loc) · 1005 Bytes
/
1073.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Foundation
var a = [Int]()
var args = readLine()!.split(separator: "E").map{String($0)}
var flag = args[0].removeFirst() == "+"
var number = args[0].split(separator: ".").map{String($0)}
var left = Array<Character>(number[0])
var right = Array<Character>(number[1])
var exponet = Int(args[1])!
func giveRight() -> Character {
let last = left.removeLast()
if left.isEmpty {
left.append("0")
}
return last
}
func receiveRight(char: Character) {
left.append(char)
}
func giveLeft() -> Character {
var first: Character = "0"
if !right.isEmpty {
first = right.removeFirst()
}
return first
}
func receiveLeft(char: Character) {
right.insert(char, at: 0)
}
if exponet > 0 {
(0..<exponet).forEach {_ in
receiveRight(char: giveLeft())
}
} else if exponet < 0 {
(exponet..<0).forEach {_ in
receiveLeft(char: giveRight())
}
}
print((flag ? "" : "-") + String(left) + (right.isEmpty ? "" : ".") + String(right))