---
# System prepended metadata

title: 第六關程式繳交處
tags: [關卡_st]

---

---
title: 第六關程式繳交處
tags: 關卡_st
---

> [第六關題目](https://hackmd.io/@futurenest/code_challenge_6)

> [程式線上編譯環境](https://replit.com/)
:::warning
繳交規範（可以複製這裡的喔）

`### 自己名字`
`#### 題目一` 
```python
程式碼
```
`#### 題目二` 
```c++
程式碼
```
:::

---
### 王政翔
#### 題目一
```cpp=
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const std::string WHITESPACE = " \n\r\t\f\v";
 
std::string ltrim(const std::string &s)
{
  size_t start = s.find_first_not_of(WHITESPACE);
  return (start == std::string::npos) ? "" : s.substr(start);
}
 
std::string rtrim(const std::string &s)
{
  size_t end = s.find_last_not_of(WHITESPACE);
  return (end == std::string::npos) ? "" : s.substr(0, end + 1);
}
 
std::string trim(const std::string &s) {
  return rtrim(ltrim(s));
}

int main() {
  string text;
  string delimiter = ",";
  string nums[256];

  getline(cin, text);

  int count = 0;
  string num;
  size_t pos = 0;
  
  while (
    (pos = text.find(delimiter)) != string::npos 
  ) {
    num = text.substr(0, pos);
    nums[count++] = trim(num);
    text.erase(0, pos + delimiter.length());
  }

  nums[count] = trim(text);

  string y;
  int j = 1;
    if(nums[count] == "9"){
      nums[count] = "0";
      for(count; count > 0; count--){
	  if(nums[count-1] == "9"){
	    nums[count-1] = "0";
	    y = nums[count-2];
	    y = atoi(y.c_str())+1;
	    j++;
	  } else {
	    y = nums[count-1];
	    break;
	  }
	}
	  cout << "[";
	  for (int i = 0; i < count-j; i++) {
    	    cout << nums[i];
          if (i < count-1) cout << ", ";
        }
        cout << atoi(y.c_str())+1 << ", ";
        for(int i = 0; i < j; i++){
	    cout << "0";
	    if(i < j-1) cout << ", ";
	  }
	  cout << "]";
      } else {
	  y = nums[count];
	  
	  cout << "[";
	  for (int i = 0; i < count; i++) {
    	    cout << nums[i];
          if (i != count) cout << ", ";
        }
          
	  cout << atoi(y.c_str())+1;
	  cout << "]";
	}
  
  return 0;
}
}
```

#### 題目二
```cpp=
#include<iostream>
using namespace std;

int main(){
    int n;
    int count = 0;
    
    cin >> n;
    
    while(n != 1){
        if(n % 2 == 0){
            n = n / 2;
            count++;
        } else {
            n = 3 * n + 1;
            count++;
        }
    }
    
    if(n == 1){
        cout << count;
        return 0;
    }
    
    return 0;
}
```
---------------------------------------------
### 林永晉
#### 題目一
```python=
lst = list(eval(input('enter numbers : ')))
ans = []
b = ' '
for i in lst:
    b += str(i)
b = int(b)
for i in str(b + 1):
    ans.append(int(i))
print(ans)
```
#### 題目二
```python=
number = eval(input('請輸入一個數字 ： '))
time = 0
i = 0
while i < 1:
    if number % 2 == 0:
        number //= 2
    else:
        number = 3 * number + 1
    time += 1
    print('第',time,'回合,number =',number)
    if number == 1:
        break
print('次數為：',time)
```
---------------------------------------------