You are viewing a single comment's thread. Return to all comments →
My clojure solution:
(require '[clojure.string :as str]) (defn split-to-int [input] (->> (str/split input #"\s") (map #(Integer/parseInt %)) (into []) ) ) (defn get-pairs [number-of-pairs] (->> (fn [] (split-to-int (read-line))) (repeatedly number-of-pairs) (into []) ) ) (defn get-has-invalid-value [pairs pairs-map] (->> pairs (filter #(not= (get pairs-map (first %)) (second %))) (count) (< 0) ) ) (let [number-of-test-cases (Integer/parseInt (read-line))] (loop [n number-of-test-cases] (if (> n 0) (do (let [number-of-pairs (Integer/parseInt (read-line)) pairs (get-pairs number-of-pairs) pairs-map (into {} pairs) has-invalid-value (get-has-invalid-value pairs pairs-map) ] (if has-invalid-value (println "NO") (println "YES") ) ) (recur (dec n)) ) ) ) )
Seems like cookies are disabled on this browser, please enable them to open this website
Functions or Not?
You are viewing a single comment's thread. Return to all comments →
My clojure solution: