見證自己的成長
題目如下
1、問題分析
就是模擬,跟着題目的意思走,外加一個計數器count就可以了
2、代碼
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int cnt = 0;
int n;
scanf("%d", &n);
int temp = n;
while(temp != 1) {
if(temp % 2 == 0) {
temp /= 2;
n = temp;
}
else if(temp % 2 == 1) {
temp = (3*n + 1) / 2;
n = temp;
}
cnt++;
}
printf("%d", cnt);
return 0;
}
3、哈哈,貼一下通過記錄叭,給自己點成就感不是