분류 전체보기 (485) 썸네일형 리스트형 [프로그래머스] 푸드 파이트 대회 - reverse() Level. 1 문제 풀이 #include #include #include #include using namespace std; string solution(vector food) { string answer = ""; string str1 = ""; string str2; for(int i=1; i [프로그래머스] 숫자짝꿍 - map Level. 1 문제 풀이 #include #include #include using namespace std; string solution(string X, string Y) { string answer = ""; map Xmap; map Ymap; for(int i=0; i 0){ minVal--; answer += to_string(i); } } if(answer == "") return "-1"; if(answer[0] == '0') return "0"; return answer; } 해결과정 자료구조 map을 사용해 key값으로 0~9를 주고 문자열에 들어있는 숫자의 개수를 각각 세어주었다. answer는 겹치는 숫자중 가장 큰 값이어야 하므로, 9부터 0까지 공통된 숫자를 탐색한다. minVa.. [프로그래머스] 가운데 글자 가져오기 - substring Level. 1 문제 풀이 class Solution { public String solution(String s) { int size = s.length(); String answer = size%2==0? s.substring(size/2-1,size/2+1) : s.substring(size/2,size/2+1); return answer; } } String substring() 1. substring(int index) - 입력받은 인자값을 index로, 해당 위치를 포함해 이후의 모든 문자열을 리턴한다. 2. substring(int beginIndex, int endIndex) - beginIndex 위치에서 endIndex 바로 전 위치까지의 값을 리턴한다. 다른 사람 풀이 class St.. [프로그래머스]문자열 내림차순으로 배치하기 Level. 1 문제 풀이 import java.util.*; class Solution { public String solution(String s) { String answer = ""; char[] arr = s.toCharArray(); Arrays.sort(arr); for(int i=0; i [프로그래머스] 두 정수의 합 - Math클래스 Level. 1 문제 풀이 class Solution { public long solution(int a, int b) { long answer = 0; int max = Math.max(a,b); int min = Math.min(a,b); for(int i = min; i (b - a + 1) * (a + b ) / 2 [프로그래머스] 문자열 내 마음대로 정렬하기 Level 1. 문제 풀이 import java.util.*; class Solution { public String[] solution(String[] strings, int n) { String[] answer = new String[strings.length]; for(int i=0; i [프로그래머스] 나누어 떨어지는 숫자 배열/ stream Level. 1 문제 풀이 import java.util.*; class Solution { public int[] solution(int[] arr, int divisor) { ArrayList list = new ArrayList(); for(int i=0; i i).toArray(); Arrays.sort(answer); return answer; } } list를 사용하여 정답을 구한 후, return타입에 맞추어 array로 변경해 주었다. ListArray -> Array list.stream().mapToInt(i -> i).toArray(); 다른 사람 풀이 import java.util.Arrays; class Solution { public int[] solution(int[] arr,.. [프로그래머스] 점프와 순간 이동 - 비트연산 Level.2 문제 풀이 #include using namespace std; int solution(int n) { int ans = 0; while(n>0){ if(n%2==0){ n/=2; } else { int num = n%2; ans += num; n -= num; } } return ans; } 다른 사람 풀이 1. #include using namespace std; int solution(int n) { int ans = 0; while(n >0) { ans += n%2; n /=2; } return ans; } 다른 사람 풀이 2. #include using namespace std; int solution(int n) { int ans=0; for(int i=0;i 이전 1 ··· 38 39 40 41 42 43 44 ··· 61 다음