---
title: 訓練場_1程式繳交處
tags: 訓練場_st
---
> [訓練場_1 題目](https://hackmd.io/@futurenest/code_training_1)
> [程式線上編譯環境](https://replit.com/)
:::warning
繳交規範(可以複製這裡的喔)
`### 自己名字`
`#### 題目一`
```python
程式碼
```
`#### 題目二`
```c++
程式碼
```
:::
---
## 頻道一
### 撿石頭
#### C++
```c++
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if (n % 4 == 0){
cout<<"False"<<endl;
}
else{
cout<<"True"<<endl;
}
return 0;
}
```
#### python
```python
n=int(input())
if n%4==0:
print(False) #n為4的倍數必輸
else:
print(True) #以外必勝
```
### 月份天數
#### C++
```c++
#include<iostream>
using namespace std;
int main()
{
int years;
int mouth;
cin>>years;
cin>>mouth;
if(years % 4 == 0){
if (mouth == 1 or mouth == 3 or mouth == 5 or mouth == 7 or mouth == 8 or mouth == 10 or mouth == 12){
cout<<"31"<<endl;
}
else if(mouth == 2){
cout<<"29"<<endl;
}
else{
cout<<"30"<<endl;
}
}
else if(years % 4 != 0){
if (mouth == 1 or mouth == 3 or mouth == 5 or mouth == 7 or mouth == 8 or mouth == 10 or mouth == 12){
cout<<"31"<<endl;
}
else if(mouth == 2){
cout<<"28"<<endl;
}
else{
cout<<"30"<<endl;
}
}
return 0;
}
```
#### python
```python
y=int(input())
m=int(input())
if m in (1,3,5,7,8,10,12):
print(31)
else:
if m==2:
if y%4==0:
print(29)
else:
print(28)
else:
print(30)
```
---
## 頻道二
### 撿石頭
```c++
#include <iostream>
using namespace std;
int main() {
int n;
cout << "n= ";
cin >> n;
if (n % 4 > 0) {
cout << "True";
}
else {
cout << "False";
}
return 0;
}
```
### 月份天數
閏年的條件
1. 西元年能被 400 整除,為閏年。
2. 西元年能被 4 整除,但不能被 100 整除,為閏年。
3. 閏年外,其餘皆為平年。
3. 閏年的2月為29日;平年的2月為28日。
```c++
#include <iostream>
using namespace std;
int main() {
int year, month;
cin >> year >> month;
if( month == 2)
{
if((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
cout << "29" << endl;
else
cout << "28" << endl;
}
else if( month == 4 || month == 6 || month == 9 || month == 11)
cout << "30" << endl;
else
cout << "31" << endl;
return 0;
}
```
---
## 頻道三
### 撿石頭
```python=
#假設兩人做出最優決策
stone = int(input('石頭數量:'))
if stone % 4 == 0:
print('False')
else:
print('True')
```
### 月份天數
```python=
year = eval(input("enter a year:"))
month = eval(input("enter a month:"))
day = 0
if 12 >= month >= 1:
if month in (1,3,5,7,8,10,12):
day = 31
elif month in (4,6,9,11):
day = 30
else:
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
day = 29 #leap year
else:
day = 28 #normal year
else:
print('wrong month')
print('%d year %d month %d day'%(year,month,day))
```
---
## 頻道四
### 撿石頭
```
a=int(input('輸入:'))
a=a%4
if a==0:
print('False')
else:
print('True')
```
### 月份天數