전체 글 (110) 썸네일형 리스트형 프로그래머스_0단계_뒤에서 5등까지C++ 문제풀이: #include #include #include #include using namespace std; vector solution(vector num_list) { vector answer; //정렬 후 sort(num_list.begin(),num_list.end()); //5번반복 for(int i=0; i 프로그래머스_0단계_0떼기_C++ 문제풀이: 문자 string은 char의 배열이라는거 잊지말자 #include #include using namespace std; string solution(string n_str) { string answer = ""; // 문자열을 왼쪽부터 순회하면서 처음으로 0이 아닌 숫자를 만나면 그 위치부터 문자열의 끝까지 반환 int i = 0; while (i < n_str.size() && n_str[i] == '0') { i++; } // 0이 아닌 숫자가 있는 위치부터 문자열의 끝까지 반환 answer = n_str.substr(i); return answer; } 프로그래머스_0단계_가장 큰 수 찾기C++ 문제풀이: #include #include using namespace std; vector solution(vector array) { vector answer; int max_val = array[0]; // 배열의 첫 번째 원소를 초기 최댓값으로 설정 int max_index = 0; // 초기 최댓값의 인덱스는 0으로 설정 // 배열을 순회하면서 최댓값과 해당 인덱스를 찾음 for(int i = 1; i max_val) { max_val = array[i]; max_index = i; } } // 최댓값과 해당 인덱스를 결과 벡터에 추가 answer.push_back(max_val); answer.push_back(max_index.. 프로그래머스_0단계_최댓값 만들기(2)C++ 문제풀이: 배열 정리해주고 max로 최댓값찾기 #include #include #include using namespace std; int solution(vector numbers) { int answer = 0; sort(numbers.begin(),numbers.end()); int value1 = numbers[0] * numbers[1]; int value2 = numbers[numbers.size()-1] *numbers[numbers.size()-2]; answer = max(value1,value2); return answer; } 프로그래머스_0단계_주사위의개수C++ 문제풀이: 사실 answer 하나로 가능하다 #include #include using namespace std; int solution(vector box, int n) { int answer = 0; int x,y,z =0; x = box[0]/n; y = box[1]/n; z = box[2]/n; answer = x * y * z; return answer; } 프로그래머스_0단계_개미군단C++ 문제풀이: #include #include using namespace std; int solution(int hp) { int answer = 0; while(hp>0) { if(hp>=5) { answer+= hp/5; hp%=5; } else if(hp>=3) { answer+= hp/3; hp%=3; } else { answer+= hp; hp=0; } } return answer; } 프로그래머스_2단계_멀리 뛰기C++ 문제풀이: 피보나치수 활용해서 풀자! #include #include using namespace std; long long solution(int n) { long long answer = 0; vectorfunc(n+1); func[0] = 1; func[1] = 1; for (int i = 2; i 프로그래머스_2단계_피보나치 수C++ 문제풀이: #include #include using namespace std; int solution(int n) { int answer = 0; vector func(n + 1); func[0] = 0; func[1] = 1; for (int i = 2; i 이전 1 2 3 4 5 6 7 8 ··· 14 다음