VisualStudio/C#
[프로그래머스/C++] 조건에 맞게 수열 변환하기 2
usingsystem
2024. 3. 7. 20:48
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/181881
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
소스
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> arr) {
int answer = 0;
vector<int> temp;
while (true)
{
temp = arr;
for (int i = 0; i < arr.size(); i++)
{
int v = arr[i];
if (v >= 50 && v % 2 == 0)
{
arr[i] = v / 2;
}
else if (v < 50 && v % 2 == 1) {
arr[i] = v * 2 + 1;
}
}
if (arr == temp)
break;
answer++;
}
return answer;
}
728x90