Skip to content

Instantly share code, notes, and snippets.

@hassi32
Created February 18, 2017 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassi32/0d9bfb82e278e45be7ba47564d9df15c to your computer and use it in GitHub Desktop.
Save hassi32/0d9bfb82e278e45be7ba47564d9df15c to your computer and use it in GitHub Desktop.
Practice extention index(like .range)
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