[프로그래머스] 정수 제곱근 판별
[프로그래머스] 정수 제곱근 판별
2020.10.11def solution(n): import math num = math.sqrt(n) if math.sqrt(n) == int(math.sqrt(n)) : #정수값이 나온다 => 제곱근의 존재 return pow(num+1, 2) #num+1 * num+1 return -1
[프로그래머스] 자연수 뒤집어 배열로 만들기
[프로그래머스] 자연수 뒤집어 배열로 만들기
2020.10.11def solution(n): return list(map(int, reversed(str(n)))) map에 대해서 자세히 공부하자
[프로그래머스] 정수 내림파순으로 배치하기
[프로그래머스] 정수 내림파순으로 배치하기
2020.10.11def solution(n): print(n) a = list(str(n)) # a라는 변수를 지정해, n의 값들을 list형태로 저장 print(a) # ['1', '1', '8', '3', '7', '2'] intList = list(map(int, a)) #intList라는 리스트를 지정해, str형태의 원소를 int형태로 지정 print(intList) #[1, 1, 8, 3, 7, 2] intList.sort(reverse=True) print(intList) #[8, 7, 3, 2, 1, 1] a = ''.join(map(str,intList)) #join을 사용하기 위해서는 다시 str형태로 지정해야한다. return int(a)
[프로그래머스] 시저 암호
[프로그래머스] 시저 암호
2020.10.11def solution(s, n): answer = [] for i in s: if i.isalpha(): if( 65 122: result = ord(i) + n - 26 answer.append(chr(result)) else : result = ord(i) + n answer.append(chr(result)) else: answer.append(' ') print(answer) return ''.join(answer)
[프로그래머스] 소수 찾기
[프로그래머스] 소수 찾기
2020.10.10def solution(n): count = 0 for i in range(1, n+1): temp_cnt = 0 for j in range(1,i+1): if i % j ==0: temp_cnt +=1 if temp_cnt == 2: count += 1 return count
[프로그래머스] K번째수
[프로그래머스] K번째수
2020.10.10def solution(array, commands): result = [] for i in commands: print(i) i_i = i[0] j_j = i[1] k_k = i[2] temp = array[int(i_i)-1:int(j_j)] temp = sorted(temp) result.append(temp[k_k-1]) return result 그냥 슬라이싱을 이용하는 문제이다. def solution(array, commands): return list(map(lambda x:sorted(array[x[0]-1:x[1]])[x[2]-1], commands)) 이렇게도 할수 있다...
[프로그래머스] 약수의 합
[프로그래머스] 약수의 합
2020.10.10def solution(n): result = 0 for i in range(1, n+1): if n % i == 0: result += i return result 약수를 result 에 계속 더한다.
[프로그래머스] 짝수와 홀수
[프로그래머스] 짝수와 홀수
2020.10.10def solution(num): if num % 2 == 0: return "Even" else : return "Odd" 기본 문제이다.
[프로그래머스] 최대공약수와 최소공배수
[프로그래머스] 최대공약수와 최소공배수
2020.10.10def solution(n, m): def gcd(x,y): while(y): x,y = y, x%y return x def lcm(x,y): result = (x*y)//gcd(x,y) return result x = gcd(n,m) y = lcm(n,m) return (x,y) 유클리오 호제법을 이용한 방법이다.
[프로그래머스] x만큼 간격이 있는 숫자
[프로그래머스] x만큼 간격이 있는 숫자
2020.10.09def solution(x, n): result = [] for i in range(1,n+1): result.append(x * i) return result
[프로그래머스] 제일 작은수 제거하기
[프로그래머스] 제일 작은수 제거하기
2020.10.09def solution(arr): if arr[0] == 10 : return [-1] else : temp = min(arr) result = arr.remove(temp) return arr min 함수를 통해서 리스트의 최소 값을 구하고, remove 함수를 통해 최소 값을 제거한다.
[백준] 4673 - 셀프 넘버 (파이썬 / C++)
[백준] 4673 - 셀프 넘버 (파이썬 / C++)
2020.04.09general = set(range(1, 10001)) change = set() for i in range(1, 10001): for j in str(i): i += int(j) change.add(i) result = general - change for i in sorted(result): print(i) #include using namespace std; bool selfnum[10001]; int main(void) { memset(selfnum, true, sizeof(selfnum)); for(int i=1; i
[백준] 15596 - 정수 N개의 합 (파이썬)
[백준] 15596 - 정수 N개의 합 (파이썬)
2020.04.09def solve(a): ans = 0 for i in a: ans += i return ans
[백준] 4344 - 평균은 넘겠지 (파이썬) (C)
[백준] 4344 - 평균은 넘겠지 (파이썬) (C)
2020.04.09import sys input = sys.stdin.readline N = int(input()) for i in range(N): list_temp = list(map(int, input().split(' '))) average = sum(list_temp[1:]) / list_temp[0] count = 0 for j in list_temp[1:]: if j > average: count += 1 print(str('%.3f' % round(count / list_temp[0] * 100, 3)) + '%') #include int main() { int num; float sum=0; float count=0; int stu_num; int score[1000]; scanf("%d", &num); ..
[백준] 8958 - OX퀴즈 (파이썬) (C++)
[백준] 8958 - OX퀴즈 (파이썬) (C++)
2020.04.09N = int(input()) for i in range(N): score = 0 cnt = 0 result = input() for j in range(len(result)): if result[j] == 'O': cnt += 1 score += cnt elif result[j] == 'X': score += 0 cnt = 0 print(score) #include #include using namespace std; int main() { int num; cin >> num; int *save_total = new int[num]; for (int i = 0; i > answer; for..