쉽다.
n, k = tuple(map(int, input().strip().split(' ')))
c = tuple(map(int, input().strip().split(' ')))
result = 100
tmp = 0
while True:
tmp = (tmp + k) % n
result -= (1 + c[tmp]*2)
if tmp == 0:
break
print(result)
n, k = tuple(map(int, input().strip().split(' ')))
c = tuple(map(int, input().strip().split(' ')))
result = 100
tmp = 0
while True:
tmp = (tmp + k) % n
result -= (1 + c[tmp]*2)
if tmp == 0:
break
print(result)
n = int(input())
n_list = list(map(int, input().strip().split(' ')))
p = { n_list[n_list[x-1]-1]:x for x in n_list}
for i in range(1, n+1):
print(p[i])
from collections import deque
n, k, q = map(int, input().strip().split(' '))
m = deque(map(int, input().strip().split(' '))) # integers
m.rotate(k) # wow...
for m_i in range(q):
print(m[int(input())]) # don't need strip(). int() will do this.
n, k, q = map(int, input().strip().split(' '))
m = list(map(int, input().strip().split(' ')))
k %= n; tmp = m[-k:]; del m[-k:]; m[0:0] = tmp
for m_i in range(q):
print(m[int(input())]) # don't need strip(). int() will do this.
public class RegistrationForm implements Cloneable {
private String name = "Zed";
private String email = "zzzed@gmail.com";
private Date dateOfBirth = new Date(1990, 1, 28);
private int weight = 60;
private Gender gender = Gender.MALE;
private Status status = Status.SINGLE;
private List children = Arrays.asList(new Child(Gender.FEMALE));
private double monthSalary = 1000;
private List favouriteBrands = Arrays.asList("Adidas", "GAP");
@Override
protected RegistrationForm clone() throws CloneNotSupportedException {
RegistrationFrom prototyped = new RegistrationForm();
prototyped.name = name;
prototyped.email = email;
prototyped.dateOfBirth = (Date)dateOfBirth.clone();
prototyped.weight = weight;
prototyped.gender = gender
prototyped.status = status;
List childrenCopy = new ArrayList();
for (Child c : children) {
childrenCopy.add(c.clone());
}
prototyped.children = childrenCopy;
prototyped.monthsCopy = monthSalary;
List brandsCopy = new ArrayList();
for (String s : favoriteBrands) {
brandsCopy.add(s);
}
prototyped.favouriteBrands = brandsCopy;
return prototyped;
}
}
사용자를 만들 때마다, clone()을 호출해서 기본값으로 쓴다.(def registration-prototype
{:name "Zed"
:email "zzzed@gmail.com"
:date-of-birth "1970-01-01"
:weight 60
:gender :male
:status :single
:children [{:gender :female}]
:month-solary 1000
:brands ["Adidas" "GAP"]})
;;return new object
(assoc registration-prototype
:name "WHO"
:email "EMAIL@DOTCOM"
:weight 52
:gender :female
:month-salary 0)
clojure는 기본적으로 불변객체이기 때문에 clone은 필요없다. #!/bin/python3
def saveThePrisoner(n, m, s):
res = (m + s - 1) % n
if res == 0:
res = n
return res
t = int(input().strip())
for _ in range(t):
n, m, s = [int(x) for x in input().strip().split(' ')]
result = saveThePrisoner(n, m, s)
print(result)
def viral_ad(n):
tmp = 2
res = 2
while n > 1:
tmp = (tmp * 3) // 2
res += tmp
n -= 1
return res
n = int(input().strip())
result = viral_ad(n)
print(result)
i,j,k = [int(x) for x in input().strip().split(' ')]
cnt = 0
for n in range(i,j):
diff = abs(n - int(str(n)[::-1])) % k
if diff == 0:
cnt += 1
print(cnt)
def bueatiful_days2():
i,j,k = [int(x) for x in input().strip().split(' ')]
res = sum(1 for x in range(i,j) if abs(int(str(x)[::-1])-x) % k == 0)
print(res)
from functools import reduce
t = int(input().strip())
for _ in range(t):
n = int(input().strip())
print(reduce(lambda a,b: a+b, (map(lambda x: pow(2,x), range(((n+1)//2)+1)))) - n%2)
ex) n = 4 111 -> range(((4+1)// 2)+1) -> range(2+1) -> 1 2 3저절로 1 2 3 이라고 나와주니 더 고맙다. 바로 pow를 이용해서 값을 구하자
[pow(2,1), pow(2,2), pow(2,3)]그리고 다 더한다. reduce로
reduce(lambda a,b: a+b, [pow(2,1), pow(2,2), pow(2,3)])그리고 even odd에 따른 차이를 뒤에 붙여준다.
- n%2
#!/bin/python3
import string
from functools import reduce
h = {key: int(value) for key, value in zip(string.ascii_lowercase, input().strip().split(' '))}
word = input().strip()
height = reduce(max, map(lambda x: h[x], word))
print(len(word)*height)
참고자료: 딕셔너리로 한꺼번에 가져오기 위한 자료.#!/bin/python3
n, k = [int(x) for x in input().strip().split(' ')]
height = [int(x) for x in input().strip().split(' ')]
print((lambda x: x if x > 0 else 0)(max(height)-k))
음... 나쁘지 않은듯. 결국 인풋을 받는 내용을 빼고는 한줄로 끝낸 거니까... 근대 이게 효율적인건가?
(use '[clojure.java.shell :only [sh]]) (sh "notepad" "a.txt") (sh "notepad" "/a.txt") (sh "pwd") (sh "nslookup") (sh "nslookup" "-query=mx" "google.com")
(defn find-mx [hostname]
(letfn [(nslookup [hostname] (sh "nslookup" "-query=mx" hostname))]
(nslookup hostname)))
(find-mx "google.com")
자세히 보아하니 뭔가 엄청 나오는 거 같다.(defn find-mx [hostname]
(letfn [(nslookup [hostname] (sh "nslookup" "-query=mx" hostname))]
(remove nil? (map #(re-matches #"(.+)mail\sexchanger(.+)" %)
(clojure.string/split (second (second (nslookup hostname))) #"\r\n")))))
(find-mx "google.com")
(["google.com\tMX preference = 10, mail exchanger = aspmx.l.google.com" "google.com\tMX
preference =
10, " " = aspmx.l.google.com"] ["google.com\tMX preference = 30, mail exchanger = alt2.aspmx.l.goog
le.com" "google.com\tMX preference = 30, " " = alt2.aspmx.l.google.com"] ["google.com\tMX
preference
= 20, mail exchanger = alt1.aspmx.l.google.com" "google.com\tMX preference = 20, " " =
alt1.aspmx.l
.google.com"] ["google.com\tMX preference = 50, mail exchanger = alt4.aspmx.l.google.com"
"google.co
m\tMX preference = 50, " " = alt4.aspmx.l.google.com"] ["google.com\tMX preference = 40, mail exchan
ger = alt3.aspmx.l.google.com" "google.com\tMX preference = 40, " " =
alt3.aspmx.l.google.com"])
user=> (count (find-mx "google.com")) 5 user=> (count (find-mx "google33.com")) 0 user=> (count (find-mx "naver.com")) 3
(count (find-mx hostname)) 0) true false) (mx-exist? "google.com") true (mx-exist? "google3134.com") false
(defn best [f xs] (reduce #(if (f % %2) % %2) xs)) (best > [1 2 3 4 5 6]) 6위 best함수는 > 함수를 받아 몸체 안에서 f로 호출한다. (이렇게 함수, 값이 이름바인딩으로 아주 일괄적)
(defun best (f xs) (reduce #'(lambda (l r) (if (funcall f l r) l r)) xs)) (best #'>' '(1 2 3 4 5 6))뭐 이상해 보이는건 내가 커먼리습을 몰라서 그런거지 절대 클로저가 좋아서 그런건 아닌듯. 그냥 차이를 알고 있자.