题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
import Foundation while let line = readLine() { let parts = line.split(separator: " ") let n = Int(line)! var array = [String]() while let str = readLine() { array.append(str) } //! 排序.这里使用 冒泡排序, for i in 0..<array.count { for j in 0..<array.count-i-1{ if array[j] > array[j+1] { array.swapAt(j,j+1) } } } //! 按照行打印出去 for str in array { print(str) } // print(array) // print(Int(parts[0])! + Int(parts[1])!) }