class Person { var height:Int var weight:Int var name:String init(_ inpt:String, _ nm:String) { let tmp = inpt.split(separator: " ").map{Int($0)!} self.height = tmp[0] self.weight = tmp[1] self.name = nm } func IsGreater(_ target:Person)-> Bool { if(self.height > target.height) { return true } if(self.height == target.height && self.weight < target.weight) { return true } return false } } let names = ["A","B","C"] var inpt = [Person]() for i in 0..<3 { inpt.append(Person(readLine()! , names[i])) } inpt.sort{$0.IsGreater($1)} for p in inpt { print(p.name) }