본문 바로가기
728x90
반응형
SMALL

C++81

[프로그래머스] 삼각형의 완성조건 (1) #include #include #include using namespace std; int solution(vector sides) { int answer = 0; sort(sides.begin(),sides.end()); //만들수 있 1, 없 2 return sides[2]} 2025. 9. 3.
[프로그래머스] 머쓱이보다 키 큰 사람 #include #include using namespace std; int solution(vector array, int height) { int answer = 0; for(auto h : array) { if(h>height) answer++; } return answer; } 2025. 9. 3.
[프로그래머스] 자릿수 더하기 #include #include using namespace std; int solution(int n) { int answer = 0; string n_str = to_string(n); for(auto c : n_str) answer += c - '0'; return answer; } 2025. 9. 3.
[프로그래머스] 최댓값 만들기 #include #include #include using namespace std; int solution(vector numbers) { sort(numbers.begin(), numbers.end()); int len = numbers.size(); return numbers[len-1] * numbers[len-2]; } 2025. 9. 3.
[프로그래머스] 세균증식 #include #include using namespace std; int solution(int n, int t) { for(int i=0; i n *=2; return n; } 2025. 9. 3.
[프로그래머스] 편지 #include #include using namespace std; int solution(string message) { return message.size()*2; } 2025. 9. 2.
[프로그래머스] 뒤집힌 문자열 #include #include using namespace std; string solution(string my_string) { string answer = ""; for(int i=my_string.size(); i>0; i--) answer.push_back(my_string.at(i-1)); return answer; } *rbegin(),rend() 메소드 사용하면 한줄로 리턴 가능 2025. 9. 2.
[프로그래머스] 짝수 홀수 개수 #include #include using namespace std; vector solution(vector num_list) { vector answer = {0,0}; for(auto n:num_list) n%2==0 ? answer[0]++:answer[1]++; return answer; } 2025. 9. 2.
[프로그래머스] 배열 뒤집기 #include #include using namespace std; vector solution(vector num_list) { vector answer; for(auto n : num_list) answer.insert(answer.begin(), n); return answer; } 2025. 9. 2.
728x90
반응형
LIST