---
# System prepended metadata

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

---

---
title: 第二關程式繳交處
tags: 關卡_st
---
<style>
.a {
    color: red;
    font-weight:bold
}
</style>

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

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

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

---
### 參考
```python
a_list = [1, 2, 3, 4, 5, 6]

print(a_list)

# 寫法一
a_list[0], a_list[5] = a_list[5], a_list[0]

# 寫法二
tmp_num = a_list[0]
a_list[0] = a_list[5]
a_list[5] = tmp_num

print(a_list)
```

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

#define add(a,b) a+b;
#define sub(a,b) a-b;
#define mul(a,b) a*b;
#define div(a,b) a/b;//定義

int main(){
	double a;
	
	double b;

	char oper;
    
	cout<<"a = ";
	cin>>a;
    
	cout<<"b = ";
	cin>>b;
    
	cout<<"operator = ";
	cin>>oper;
	
	switch(oper){
		case '+' : cout << add(a,b); break;
		case '-' : cout << sub(a,b); break;
		case '*' : cout << mul(a,b); break;
		case '/' : cout << div(a,b); break;//判斷符號
		default: break;//若都沒有則跳離
	}
	
	return 0;
}
```
#### 題目二
```cpp=
#include<iostream>
using namespace std;

int main(){
	int array[0];
	
	int temp; //暫存器 
	
	cout<<"num1 = ";
	cin>>array[0];
    
	cout<<"num2 = ";
	cin>>array[1];
    
	cout<<"num3 = ";
	cin>>array[2];

	if(array[1] > array[0]){
		temp = array[0];
		array[0] = array[1];
		array[1] = temp;    //交換位置
        
		if (array[2] > array[0]){
		    temp = array[0];
		    array[0] = array[2];
		    array[2] = temp;
		}    //交換位置
	}
	else if (array[2] > array[0]){
		temp = array[0];
		array[0] = array[2];
		array[2] = temp;
	}    //交換位置
	
	cout<<array[0]<<endl; //此時array[0]等於最大值
	
	return 0;
}
```
#### 題目三
```cpp=
#include<iostream>
using namespace std;

int main(){
	int i = 1;
	
	int size;

	cout << "size = ";
	cin >> size;
	
	cout << "[";
	while(i <= size){
		cout << i; //打印
		if(i != size){
			cout << ", "; //判斷是否為最後一項
		}
		i++;
	}
	cout << "]";

	return 0;
}
```
#### 題目四
```cpp=
#include<iostream>
using namespace std;

int main(){
	
	int n;
	
	int i = 0;
	
	int i1;
	
	int i2;
	
	int temp;//寄存器 
	
	cout<<"n = ";
	cin>>n;
	
	int a[n] = {};
	
	while(i < n){
		cin>>a[i];
		i++;
	}
    //存進陣列

	cout<<"index1 = ";
	cin>>i1;
	cout<<"index2 = ";
	cin>>i2;
	
	temp = a[i1];
	a[i1] = a[i2];
	a[i2] = temp;
	//轉換位置
	
	if(i1 >= n or i2 >= n){
		cout<<"輸入錯誤";
		return -1;
	}
	if(i1 < 0 or i2 < 0){
		cout<<"輸入錯誤";
		return -1;
	}
	//若輸入超過陣列長度時，則為輸入錯誤
    
	cout<<"[";
	for(i = 0;i < n;i++){
		cout<<a[i];
		if(i != n-1){
			cout<<", "; //判斷是否最後一項
		}
	}
	cout<<"]";
	
	
	return 0;
}
```
### 林永晉
#### 題目一
```python=
a = int(input('a = '))
b = int(input('b = '))
op = input('operatur = ')
if op == '+':
    print(a + b)
elif op == '-':
    print(a - b)
elif op == '*':
    print(a * b)
elif op == '/':
    print(a / b)
else:
    print('輸入錯誤')
```
#### 題目二
```python=
num1 = int(input('num1 = '))
num2 = int(input('num2 = '))
num3 = int(input('num3 = '))
print(max(num1, num2, num3))
```
#### 題目三
```python=
num = int(input('size = '))
print(list(range(1,num + 1)))
```
```python=
LI = []
n = int(input('size = '))
for i in range(1, n + 1):
    LI.append(i)
print(LI)
```
#### 題目四
```python=
ans = input("請輸入整數陣列:")
ans = list(eval(n) for n in ans.split())
print(ans)
index1 = int(input('index1 = '))
index2 = int(input('index2 = '))
ans[index1],ans[index2] = ans[index2],ans[index1]
print(ans)
```
```python=
abc = []
digit = int(input("要輸入的數量 :"))
for i in range(digit):
    abc.append(int(input("請輸入陣列資料:")))
index1 = int(input('index1 = '))
index2 = int(input('index2 = '))
abc[index1],abc[index2] = abc[index2],abc[index1]
print(abc)
```
### 楊苡若
#### 題目一
```python=
a = int(input('a = '))
b = int(input('b = '))
operator = input('operator = ')

if operator == "+":
  print(a+b)

elif operator == "-":
  print(a-b)

elif operator == "*":
  print(a*b)

elif operator == "/":
  print(a/b)

else:
  print("請重新輸入")  
```
#### 題目二
```python=
num1 = int(input('num1 = '))
num2 = int(input('num2 = '))
num3 = int(input('num3 = '))

print(max(a,b,c))
#取出最大值
```
#### 題目三
```python=
#<方法1>

size = int(input('size = '))
size = size+1 
#陣列起始值為0

sum = 1
#從多少開始

number = list(range(sum,a))
print(number)
```

```python=
#<方法2> for 迴圈

size = int(input('size = '))

my_list = []

sum = 1
#數字皆從1開始

for i in range(size):
  my_list.append(sum)
  sum = sum+1
  
print(my_list)
```

#### 題目四
```python=
length_list = int(input('輸入的長度：'))

my_list = []

for i in range(length_list):

  Integer = int(input('請輸入一個整數：'))
  my_list.append(Integer)

index1 = int(input('index1 = '))
index2 = int(input('index2 = '))

my_list[index1], my_list[index2] = my_list[index2], my_list[index1]
#後來結果輸入至之前陣列位置 

print(my_list)
```






### 張云綺
#### 題目一
```python=
a = int(input('輸入數字'))
b = int(input('輸入數字'))
y = input('operator= ')

if y == '+':
  print(a+b)

elif y == '-':
  print(a-b)

elif y == '*':
  print(a*b)

elif y == '/':
 print(a/b)
else: 
 print ('重新輸入')
```
#### 題目二
```python
a = input(" ")
b = input(" ")
c = input(' ')
print (max(a,b,c))
```
#### 題目三
```python=
#較難
a_list = [ ]

size = int(input('請輸入size大小'))
for i in range(1,size+1):
  a_list.append(i)
print(a_list)
```
#### 題目四
```python=
my_list = [] #輸入任何元素

my_list[] , my_list[] = my_list[] , my_list[] 
#輸入想對調的位置
print(my_list)
```
### 楊芷瑜
#### 題目一
```python=
a=int(input("輸入任何數字")) #將字串轉為整數型別
b=int(input("輸入任何數字"))
op=input("輸入運算:+,-,/,*")
if op=="+":           #假設op輸入加減乘除
   print(a+b)
elif op=="-":          
     print(a-b)
elif op=="*":
     print(a*b) 
elif op=="/":
    print(a/b)         
else:                 #如果上述假設皆不成立
   print(輸入錯誤)   #如果輸入不為原設定運算則"輸入錯誤"

```
#### 題目二
```python=
num1=input("輸入任何數字")
num2=input("輸入任何數字")
num3=input("輸入任何數字")
print(max(num1,num2,num3))  #比較數字大小
```
#### 題目三
```python=
i=1
size=int(input("size="))
print(list(range(i,size+1))) #數列->範圍(從i到a-1,故還要加一)
```
#### 題目四
```python=
w=[]
n=int(input("輸入數字範圍="))
for i in range(n):      #重複循環直到指定數字
    w.append(int(input("輸入數字內容="))) #append=增加該欄位數字
index1=int(input("index1="))
index2=int(input("index2="))
w[index1],w[index2]=w[index2],w[index1]  #交換所規定位置
print(w)

```


### 郭亮霆
#### 題目一
```python=
a=int(input("請輸入a值"))
b=int(input("請輸入b值"))
c=str(input("opeator"))
if c=="+":
    print(a+b)
elif c=="-":
    print(a-b)
elif c=="8":
    pritn(a*b)
elif c=="/":
    print(a/b)
```  
#### 題目二
```python=
num1=input("number1")
num2=input("number2")
num3=input("number3")
print(max(num1,num2,num3))
```
#### 題目三
```python=
i=int(input("size="))
print(list(range(1,i+1)))
```
#### 題目四
```python=
a,b,c,d=int(input("[size=]"))
```


### 余靜玟


### 張若聞
#### 題目一
```c++=
#include <iostream>
using namespace std;
int add(int,int);
int sub(int,int);
int mul(int,int);
float divide(int,int);
int main() {
    int a, b;
    char op;
    cin >> a; 
    cin >> op;
    cin >> b;

    switch (op) {
        case '+': cout << add(a,b); break;
        case '-': cout << sub(a,b); break;
        case '*': cout << mul(a,b); break;
        case '/': cout << divide(a,b); break;
        default: break;
	    }

    return 0;
}

int add(int a, int b) {
  return a + b;
}

int sub(int a, int b) {
  return a - b;
}

int mul(int a, int b) {
  return a * b;
}

float divide(int a, int b) {
  return a / b;
}
```
#### 題目二
```c++=
#include <iostream>
using namespace std;
int main() {
    int num1, num2, num3;
    int max;
    
    cin >> num1 >> num2 >> num3;

    max = num1;
    if (max < num2) {
       max = num2;
    }
    
    if (max < num3) {
       max = num3;  
    }
    
    cout << max;

    return 0;
}
```
#### 題目三
```c++=
#include <iostream>
using namespace std;

int main(){
    int size;
    
    cin >> size;
    
    cout << "[";

    for (int i = 1; i <= size; i++) {
        cout << i;
        if (i != size) cout << ", ";
    }
    
    cout << "]" << endl;
}
```
#### 題目四
```c++=
#include <iostream>
using namespace std;
int main() {
    int n = 4, index1, index2, t;
    int i = 0;
    int a[n];
    
    while (i < n) {
		  cin >> a[i];
		  i++;
    }
    
    cin >> index1 >> index2;

    t = a[index1];
	  a[index1] = a[index2];
	  a[index2] = t;

    cout << "[";
    for (i = 0; i < n; i++) {
        cout << a[i];
        if (i != n - 1) {
            cout << ", ";
        }
    }
    cout << "]";
    
    return 0;
}
```

### 黃冠霖
#### 題目一
```python=
a = int(input())
operator = input()
b = int(input())

if operator == '+':
    print(a+b)
elif operator == '-':
    print(a-b)
elif operator == '*':
    print(a*b)
elif operator == '/':
    print(a/b)
```
#### 題目二
```python=
num1 = int(input())
num2 = int(input())
num3 = int(input())
if num1 > num2 and num1 > num3:
    print(num1)
elif num2 > num1 and num2 > num3:
    print(num2)
elif num3 > num1 and num3 > num2:
    print(num3)
```
#### 題目三
```python=
size = int(input())
for i in range(size):
    print(i+1)
    i = i + 1
```
#### 題目四
```python=
n = int(input())
a = []
for i in range(n):  #用for迴圈新增數值
    a.append(int(input()))
index1 = int(input())
index2 = int(input())
a[index1],a[index2] = a[index2],a[index1]  #數值交換
print(a)
```
### 鐘宇恩
#### 題目一
```python=
a = int(input('please type a number a = '))
b = int(input('please type a number b = '))
operator = input('please choose an operator [ + or - or * or / 1] ')

if operator == '+':
  print(a + b)
elif operator == '-':
  print(a - b)
elif operator == '*':
  print(a * b)
elif operator == '/':
  print(int(a / b))
```
#### 題目二
```python=
a = int(input('please type a number a = '))
b = int(input('please type a number b = '))
c = int(input('please type a number c = '))

print(max(a,b,c))
```
#### 題目三
```python=
size = int(input('please type a number size =
'))
i = 1
print(list(range(i,size+1)))
```
#### 題目四
```python=
n = int(input('please type the len of the list n = '))
index1 = int(input('Which number of index are you going to exchange index1 = '))
index2 = int(input('Which number of index are you going to exchange index2 = '))
s = []
for i in range(n):
  s.append(i+1)

s[index1],s[index2] = s[index2],s[index1]
print(s)
#print(list(range(1,n+1)))
```
### 鍾宇哲
#### 題目一
```python=
a = int (input ( ))
b = int (input ( ))
operator = input ( )
if operator == '+':
  print(a + b)
elif operator == '-':
  print(a - b)
elif operator == '*':
  print(a * b)
elif operator == '/':
  print(int(a / b))
 ```
 #### 題目二
 ```python=
a = int (input ( ))
b = int (input ( ))
c = int (input ( ))
print(max(a,b,c))
 ```
#### 題目三
 ```python=
i = int(input("size="))
print (list(range(1,i+1)))
 ```
 #### 題目四
 ```python=
 n = int(input( ))
index1 = int(input( )) 
index2 = int(input( ))
s = []
for i in range(n):
  s.append(i+1)

s[index1],s[index2] = s[index2],s[index1]
print(s)
 ```