python

프로그래머스/Level1

[Level 1] 소수 만들기 (C++/Python)

C++) #include #include #include #define MAX_NUM 3000 // 입력된 값들의 최대 합은 998+999+1000 using namespace std; array prime; int solution(vector nums) { int answer = 0; // 소수 먼저 구하기 for(int i = 2; i * i

프로그래머스/Level1

[Level 1] 모의고사 (C++/Python)

C++) #include #include #include using namespace std; vector solution(vector answers) { vector answer; int scores[3] = {0,}; vector s1 = {1,2,3,4,5}; vector s2 = {2,1,2,3,2,4,2,5}; vector s3 = {3,3,1,1,2,2,4,4,5,5}; // 정답 순회하면서 수포자가 찍은 답과 일치하면 점수 더하기 for(int idx = 0; idx < answers.size(); idx++) { if(answers[idx] == s1[idx % s1.size()]) scores[0]++; if(answers[idx] == s2[idx % s2.size()]) scores[..

프로그래머스/Level1

[Level1] 콜라 문제 (C++/Python)

C++) #include #include using namespace std; int solution(int a, int b, int n) { int answer = 0; while(n >= a) { answer += ((n/a) * b); n = (((n/a) * b) + n%a); } return answer; } // (n/a * b) == 교환한 콜라병 // n%a == a개를 채우지 못해 교환하지 못한 콜라병 Python) def solution(a, b, n): ans = 0 while n >= a: ans += ((n//a) * b) n = ((n//a)*b) + (n%a) return ans

백준 1/자료구조

[백준 2493] 탑 (C++/Python)

C++) #include #include #include using namespace std; int main(void){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int temp = 0; stack st; for(int idx = 1; idx > temp; // 스택이 비어있지 않고 top에 있는 값이 현재 기준 값보다 작을때까지 뽑아내기 while (!st.empty() && st.top().second < temp) st.pop(); // 만약 스택이 비어있으면 현재 탑보다 높은 탑이 없다는 뜻이므로 0 출력 // 비어있지 있지 않다면 현재 탑보다 높은 탑이 있다는 뜻이므로 가장 높은 탑의 번호 출력 if (st.em..

백준 1/자료구조

[백준 1406] 에디터 (Python)

import sys read = sys.stdin.readline st1 = list(read().rstrip()) st2 = [] t = int(read().rstrip()) for _ in range(t): arr = read().rstrip().split() if arr[0] == 'L' and len(st1) > 0: st2.append(st1[-1]) st1.pop() elif arr[0] == 'D' and len(st2) > 0: st1.append(st2[-1]) st2.pop() elif arr[0] == 'B' and len(st1) > 0: st1.pop() elif arr[0] == 'P': st1.append(arr[1]) print(''.join(st1) + ''.join(rev..

백준 1/기타

[백준 3273] 두 수의 합 (Java / Python)

import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; import java.util.Arrays; public class Main{ static int[] arr; public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); arr = new int[n]; StringTokenizer s..

프로그래머스/Level1

[Level 1] 시저 암호 (C++/Python)

C++) #include #include #include using namespace std; string solution(string s, int n) { string answer = ""; for(int i = 0; i < s.size(); i++){ int pos = s.at(i) + n; if('a'

프로그래머스/Level1

[Level 1] 수박수박수박수박수박수? (C++/Python)

C++) #include using namespace std; string solution(int n) { string answer = ""; for(int i = 0; i < n/2; i++) answer += "수박"; answer += (n%2 == 1) ? "수" : ""; return answer; } Python) def solution(n): return "수박" * (n//2) + "수" * (n%2)

프로그래머스/Level1

[Level 1] 문자열을 정수로 바꾸기 (C++/Python)

C++) #include #include using namespace std; int solution(string s) { if (isdigit(s[0])) return stoi(s); else if (s[0] == '+') return stoi(s.substr(1)); else return stoi(s.substr(1)) * -1; } Python) def solution(s): if s[0] == '-': return -1 * int(s[1:]) elif s[0] == '+': return int(s[1:]) return int(s)

프로그래머스/Level1

[Level 1] 서울에서 김서방 찾기 (C++/Python)

C++) #include #include using namespace std; string solution(vector seoul) { int pos = 0; for(auto name : seoul){ if (name == "Kim") break; pos++; } return "김서방은 " + to_string(pos) +"에 있다"; } Python) def solution(seoul): return "김서방은 {}에 있다".format(seoul.index("Kim"))

핑구ovo
'python' 태그의 글 목록 (5 Page)