ES6 자바스크립트 객체
·
Language/JavaScript
const dog = { name : '멍멍이', age : 2, 'key with space' : 'asdf' } 키 값에 공백이 있는 경우 ' '로 감싸주면 된다. const ironMan = { name: '토니 스타크', actor : '로버트 다우니 주니어', alias : '아이언맨', }; const captainAmerica = { name : '스티븐 로저스', actor : '크리스 에반스', alias : '캡틴 아메리카' }; function print(hero) { const text = `${hero.alias}(${hero.name}) 역할을 맡은 배우는 ${hero.actor}입니다.` console.log(text) } print(ironMan) print(captainAm..
ES6 화살표 함수
·
Language/JavaScript
const adds = (a,b) => { return a + b } //위와 동일한 표현 const add = (a, b) => a + b; const hello = name =>{ console.log(`Hello, ${name}`); } const sum = add(1,2); const sum1 = adds(1,2); hello('velopert') console.log(sum); console.log(sum1);
자바스크립트 논리연산자 실행 순서
·
Language/JavaScript
not -> and -> or 순서로 실행된다. // NOT ! // AND && // OR || const value = !((true && false) || (true && false) || !false); // !(true && da;se || true && false || true) // !(false || false || true) // !(true) // false console.log(value);
null과 undefined의 차이
·
Language/JavaScript
let criminal; console.log(criminal); // 결과는 undefined // null은 없고 undefined는 아직 지정해주지 않은 것.
프로그래머스 - 체육복
·
Algorithm/프로그래머스
체육복을 도난당한 학생의 번호와 여벌이 있는 학생의 번호가 같을 경우를 고려해야하는 문제. def solution(n, lost, reserve): # 체육복을 도난당한 학생이 여벌이 있을경우를 고려하여 둘 다 제거 real_lost = list(set(lost) - set(reserve)) real_reserve = list(set(reserve) -set(lost)) for i in range(len(real_reserve)): if real_reserve[i] -1 in real_lost: real_lost.remove(real_reserve[i] -1) elif real_reserve[i] + 1 in real_lost: real_lost.remove(real_reserve[i] + 1) answ..
백준 15649 - N과 M
·
Algorithm/백준
python의 permutation내장함수를 통해 풀 수 있는 문제 itertools.permutations()는 순열을 구해주고 itertools.combinations()는 조합을 구해준다. from itertools import permutations n, m = map(int,input().split()) number = permutations(range(1,n+1),m) for i in number: print(*i) www.acmicpc.net/problem/15649 15649번: N과 M (1) 한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해 www.a..
백준 10773 - 제로 python
·
Algorithm/백준
스택을 활용하는 기본 문제이다. import sys input = sys.stdin.readline K = int(input()) stack = [] for i in range(K): num = int(input()) if num == 0: stack.pop(-1) else: stack.append(num) print(sum(stack)) www.acmicpc.net/problem/10773 10773번: 제로 첫 번째 줄에 정수 K가 주어진다. (1 ≤ K ≤ 100,000) 이후 K개의 줄에 정수가 1개씩 주어진다. 정수는 0에서 1,000,000 사이의 값을 가지며, 정수가 "0" 일 경우에는 가장 최근에 쓴 수를 지우고, 아닐 경 www.acmicpc.net
백준 10828 - 스택 python
·
Algorithm/백준
파이썬으로 스택의 기능을 구현하는 문제이다. import sys input = sys.stdin.readline stack =[] N = int(input()) for i in range(N): order = input().split() if order[0] == 'push': stack.append(order[1]) if order[0] == 'pop': if len(stack) == 0: print(-1) else: print(stack.pop(-1)) if order[0] == 'size': print(len(stack)) if order[0] == 'empty': if len(stack) == 0: print(1) else: print(0) if order[0] == 'top': if len(st..
백준 4344 - 평균은 넘겠지 파이썬
·
Algorithm/백준
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): case = list(map(int, input().split())) avg_score = sum(case[1:]) / case[0] cnt = 0 for score in case[1:]: if score > avg_score: cnt += 1 # n번째까지만 표현하고 반올림하고 싶을때 사용할 수 있는 round 내장함수 print("%.3f" % round((cnt/case[0]) * 100, 3) + '%') # print(f'{class_avg:.3f}') python 3.6 버전부터 나온 fstring 문자열 포매팅을 활용해서도 답을 출력할 수 있다. www.acmi..
takoyummy
'분류 전체보기' 카테고리의 글 목록 (21 Page)