Created
February 18, 2017 05:47
-
-
Save hassi32/0d9bfb82e278e45be7ba47564d9df15c to your computer and use it in GitHub Desktop.
Practice extention index(like .range)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String { | |
func index(character: Character) -> String.Index? { | |
let index = self.characters.enumerated().filter { (idx, c) in c == character }.first?.0 | |
guard let offset = index else { | |
return nil | |
} | |
return self.index(self.startIndex, offsetBy: offset) | |
} | |
} | |
let line1: String = readLine()! | |
let n: Int = Int(line1)! | |
if 0 <= n && n <= 9 { | |
let m: Int = Int(readLine()!)! | |
if 0 <= m && m <= 100 { | |
var array = [Int]() | |
for i in 0..<m { | |
let line2: String = readLine()! | |
let r_i: Int = Int(line2)! | |
if 0 <= r_i && m <= 1000 { | |
let char = Character(line1) | |
if line2.index(character: char) == nil { | |
array.append(r_i) | |
} | |
} | |
} | |
if array.count != 0 { | |
for i in array { | |
print(i) | |
} | |
} else { | |
print("none") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment