문제접근
1.
첫번째 접근
•
n을 입력을 받게 되면 짝수일때와 홀수일때의 각각의 경우에 대해서 연산 진행
•
연산을 진행하면서 큰 값을 계속 업데이트를 함
•
1을 만나게 되면 그 동안의 업데이트를 통해 최신화된 큰 값을 출력
//pseudo code
cin >> t
while (t--)
{	
	cin >> n
	while (n > 1) //1보다 크면 동작
	{
		if (n % 2 == even)
			n /= 2;
		else 
			n = n * 3 + 1
		if (max < n)
			max = n;
	}
	cout << max << "\n"
}
C++
복사
놓쳤던 부분
코드
2016KB
36ms
#include <iostream>
void input_setting()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
}
void solution()
{
	int t;
	int n;
	int max;
	std::cin >> t;
	while (t--)
	{
		std::cin >> n;
		max = n;
		while (n > 1)
		{
			if (n % 2 == 0)
				n /= 2;
			else
				n = n * 3 + 1;
			if (max < n)
				max = n;
		}
		std::cout << max << "\n";
	}
}
int main(void)
{
	input_setting();
	solution();
	return (0);
}
C++
복사



