2023年7月2日 星期日

ZeroJudge python解答:a216. 數數愛明明

       問題:題目中有個關鍵,那就是[python如何實現對文件結束符(EOF)的判斷]
我決定用sys.stdin來處理這道題:
import sys
for line in sys.stdin:
    if line != "\n":
   
    else:
        break

我的最新解答:參考資料來源4.使用迴圈產生費波那契數列,利用迴圈來寫,發現可以通過。

import sys
for line in sys.stdin:
    if line != "\n":
        n = int(line)
        funf = []
        farr = []
        fung = []
        garr = []
        for i in range(1,n+1):
            if i == 1:
                f = 1
                g = 1
                funf.append(f)
                farr.append(f)
                fung.append(g)
                garr.append(g)
            else:
                f = i+funf[0]
                g = f+fung[0]
                del funf[0]
                del fung[0]
                funf.append(f)
                fung.append(g)
            farr.append(f)
            garr.append(g)
        print(farr[n],garr[n])
    else:
        break

測試後結果:


我的第一次解答:參考資料來源3.運用遞迴產生費波那契數列,採用遞迴的方式來寫,發現只能得50%

import sys

def funf(n):
    if n > 1:
        return n + funf(n-1)
    return 1

def fung(n):
    if n > 1:
        return funf(n)+fung(n-1)
    return 1

for line in sys.stdin:
    if line != "\n":
        ln = int(line)
        print(funf(ln),fung(ln))
    else:
        break

測試後結果:




資料來源:
1.高中生解題系統
2.python如何實現對文件結束符(EOF)的判斷
3.運用遞迴產生費波那契數列



ZeroJudge解題
ZeroJudge python解答:a004. 文文的求婚
ZeroJudge python解答:a005. Eva 的回家作業
ZeroJudge python解答:a006. 一元二次方程式
ZeroJudge python解答:a009. 解碼器
ZeroJudge python解答:a010. 因數分解
ZeroJudge python解答:a015. 矩陣的翻轉
ZeroJudge python解答:a017. 五則運算
ZeroJudge python解答:a020. 身分證檢驗
ZeroJudge python解答:a021. 大數運算
ZeroJudge python解答:a022. 迴文
ZeroJudge python解答:a024. 最大公因數(GCD)
ZeroJudge python解答:a034. 二進位制轉換
ZeroJudge python解答:a038. 數字翻轉
ZeroJudge python解答:a040. 阿姆斯壯數
ZeroJudge python解答:a042. 平面圓形切割
ZeroJudge python解答:a044. 空間切割
ZeroJudge python解答:a053. Sagit's 計分程式
ZeroJudge python解答:a054. 電話客服中心
ZeroJudge python解答:a058. MOD3
ZeroJudge python解答:a059. 完全平方
ZeroJudge python解答:a065. 提款卡密碼
ZeroJudge python解答:a104. 排序
ZeroJudge python解答:a121. 質數又來囉
ZeroJudge python解答:a148. You Cannot Pass?!
ZeroJudge python解答:a149. 乘乘樂
ZeroJudge python解答:a215. 明明愛數數
ZeroJudge python解答:a216. 數數愛明明
ZeroJudge python解答:a224. 明明愛明明
ZeroJudge python解答:a225. 明明愛排列
ZeroJudge python解答:a244. 新手訓練 ~ for + if
ZeroJudge python解答:a248. 新手訓練 ~ 陣列應用
ZeroJudge python解答:a263. 日期差幾天
ZeroJudge python解答:a410. 解方程
ZeroJudge python解答:a528. 大數排序
ZeroJudge python解答:a647. 投資專家
ZeroJudge python解答:a693. 吞食天地
ZeroJudge  python解答:a694. 吞食天地二
ZeroJudge python解答:a738. 最大公约数

 

 

ZeroJudge python解答:a215. 明明愛數數


 
        問題:題目中有個關鍵,那就是[python如何實現對文件結束符(EOF)的判斷]
我決定用sys.stdin來處理這道題:
import sys
for line in sys.stdin:
    if line != "\n":
   
    else:
        break 

我的解答:

import sys
for line in sys.stdin:
    if line !="\n":
        ln,lm = line.split(" ")
        n = int(ln)
        m = int(lm)
        sum = n
        k = 1
        while sum <= m:
            n = n + 1
            sum = sum + n
            k = k + 1
        print(k)
    else:
        break

測試後結果:

資料來源:
1.高中生解題系統
2.python如何實現對文件結束符(EOF)的判斷

 


ZeroJudge解題
ZeroJudge python解答:a004. 文文的求婚
ZeroJudge python解答:a005. Eva 的回家作業
ZeroJudge python解答:a006. 一元二次方程式
ZeroJudge python解答:a009. 解碼器
ZeroJudge python解答:a010. 因數分解
ZeroJudge python解答:a015. 矩陣的翻轉
ZeroJudge python解答:a017. 五則運算
ZeroJudge python解答:a020. 身分證檢驗
ZeroJudge python解答:a021. 大數運算
ZeroJudge python解答:a022. 迴文
ZeroJudge python解答:a024. 最大公因數(GCD)
ZeroJudge python解答:a034. 二進位制轉換
ZeroJudge python解答:a038. 數字翻轉
ZeroJudge python解答:a040. 阿姆斯壯數
ZeroJudge python解答:a042. 平面圓形切割
ZeroJudge python解答:a044. 空間切割
ZeroJudge python解答:a053. Sagit's 計分程式
ZeroJudge python解答:a054. 電話客服中心
ZeroJudge python解答:a058. MOD3
ZeroJudge python解答:a059. 完全平方
ZeroJudge python解答:a065. 提款卡密碼
ZeroJudge python解答:a104. 排序
ZeroJudge python解答:a121. 質數又來囉
ZeroJudge python解答:a148. You Cannot Pass?!
ZeroJudge python解答:a149. 乘乘樂
ZeroJudge python解答:a215. 明明愛數數
ZeroJudge python解答:a216. 數數愛明明
ZeroJudge python解答:a224. 明明愛明明
ZeroJudge python解答:a225. 明明愛排列
ZeroJudge python解答:a244. 新手訓練 ~ for + if
ZeroJudge python解答:a248. 新手訓練 ~ 陣列應用
ZeroJudge python解答:a263. 日期差幾天
ZeroJudge python解答:a410. 解方程
ZeroJudge python解答:a528. 大數排序
ZeroJudge python解答:a647. 投資專家
ZeroJudge python解答:a693. 吞食天地
ZeroJudge  python解答:a694. 吞食天地二
ZeroJudge python解答:a738. 最大公约数

 

 

ZeroJudge python解答:a149. 乘乘樂

 

我的解答:
T = int(input())
for i in range(T):
    NumStr = input()
    Num = int(NumStr)
    digits = len(NumStr)
    product = 1
    for j in range(digits):
        if j == 0:
            product = product * (Num%10)
        elif j == digits-1:
            product = product * (Num//(10**j))
        else:
            product = product * (Num//(10**j)%10)
    print(product)
測試後結果:

資料來源:
1.高中生解題系統
2.

ZeroJudge解題
ZeroJudge  python解答:a001. 哈囉

ZeroJudge python解答:a004. 文文的求婚
ZeroJudge python解答:a005. Eva 的回家作業
ZeroJudge python解答:a006. 一元二次方程式
ZeroJudge python解答:a009. 解碼器
ZeroJudge python解答:a010. 因數分解
ZeroJudge python解答:a015. 矩陣的翻轉
ZeroJudge python解答:a017. 五則運算
ZeroJudge python解答:a020. 身分證檢驗
ZeroJudge python解答:a021. 大數運算
ZeroJudge python解答:a022. 迴文
ZeroJudge python解答:a024. 最大公因數(GCD)
ZeroJudge python解答:a034. 二進位制轉換
ZeroJudge python解答:a038. 數字翻轉
ZeroJudge python解答:a040. 阿姆斯壯數
ZeroJudge python解答:a042. 平面圓形切割
ZeroJudge python解答:a044. 空間切割
ZeroJudge python解答:a053. Sagit's 計分程式
ZeroJudge python解答:a054. 電話客服中心
ZeroJudge python解答:a058. MOD3
ZeroJudge python解答:a059. 完全平方
ZeroJudge python解答:a065. 提款卡密碼
ZeroJudge python解答:a104. 排序
ZeroJudge python解答:a121. 質數又來囉
ZeroJudge python解答:a148. You Cannot Pass?!
ZeroJudge python解答:a149. 乘乘樂
ZeroJudge python解答:a215. 明明愛數數
ZeroJudge python解答:a216. 數數愛明明
ZeroJudge python解答:a224. 明明愛明明
ZeroJudge python解答:a225. 明明愛排列
ZeroJudge python解答:a244. 新手訓練 ~ for + if
ZeroJudge python解答:a248. 新手訓練 ~ 陣列應用
ZeroJudge python解答:a263. 日期差幾天
ZeroJudge  python解答:a694. 吞食天地二
ZeroJudge python解答:a738. 最大公约数
 





2023年6月28日 星期三

ZeroJudge python解答:a058. MOD3

a058. MOD3 - 高中生程式解題系統 (zerojudge.tw)

我的解答:

num = int(input())
k3 = 0
k3R1 = 0
k3R2 = 0
for i in range(0,num):
    inNum = int(input())
    if inNum%3 == 0:
        k3=k3 + 1
    elif inNum%3 == 1:
        k3R1 = k3R1 + 1
    elif inNum%3 == 2:
        k3R2 = k3R2 + 1

print(k3,k3R1,k3R2)
測試後結果:

資料來源:
1.高中生解題系統
2.

ZeroJudge解題
ZeroJudge  python解答:a001. 哈囉

ZeroJudge python解答:a004. 文文的求婚
ZeroJudge python解答:a005. Eva 的回家作業
ZeroJudge python解答:a006. 一元二次方程式
ZeroJudge python解答:a009. 解碼器
ZeroJudge python解答:a010. 因數分解
ZeroJudge python解答:a015. 矩陣的翻轉
ZeroJudge python解答:a017. 五則運算
ZeroJudge python解答:a020. 身分證檢驗
ZeroJudge python解答:a021. 大數運算
ZeroJudge python解答:a022. 迴文
ZeroJudge python解答:a024. 最大公因數(GCD)
ZeroJudge python解答:a034. 二進位制轉換
ZeroJudge python解答:a038. 數字翻轉
ZeroJudge python解答:a040. 阿姆斯壯數
ZeroJudge python解答:a042. 平面圓形切割
ZeroJudge python解答:a044. 空間切割
ZeroJudge python解答:a053. Sagit's 計分程式
ZeroJudge python解答:a054. 電話客服中心
ZeroJudge python解答:a058. MOD3
ZeroJudge python解答:a059. 完全平方
ZeroJudge python解答:a065. 提款卡密碼
ZeroJudge python解答:a104. 排序
ZeroJudge python解答:a121. 質數又來囉
ZeroJudge python解答:a148. You Cannot Pass?!
ZeroJudge python解答:a149. 乘乘樂
ZeroJudge python解答:a215. 明明愛數數
ZeroJudge python解答:a216. 數數愛明明
ZeroJudge python解答:a224. 明明愛明明
ZeroJudge python解答:a225. 明明愛排列
ZeroJudge python解答:a244. 新手訓練 ~ for + if
ZeroJudge python解答:a248. 新手訓練 ~ 陣列應用
ZeroJudge python解答:a263. 日期差幾天
ZeroJudge  python解答:a694. 吞食天地二
ZeroJudge python解答:a738. 最大公约数
 





ZeroJudge python解答:a059. 完全平方

我的解答:
import math
n = int(input())
for i in range(1,n+1):
    a = int(input())
    b = int(input())
    a1 = math.ceil(math.sqrt(a))
    b1 = int(math.sqrt(b))
    num =0
    for j in range(a1,b1+1):
        num = num + j**2
    print('Case '+str(i)+': '+str(num))
檢測結果:

 
 
資料來源:
1.高中生解題系統
2.

ZeroJudge解題
ZeroJudge  python解答:a001. 哈囉

ZeroJudge python解答:a004. 文文的求婚
ZeroJudge python解答:a005. Eva 的回家作業
ZeroJudge python解答:a006. 一元二次方程式
ZeroJudge python解答:a009. 解碼器
ZeroJudge python解答:a010. 因數分解
ZeroJudge python解答:a015. 矩陣的翻轉
ZeroJudge python解答:a017. 五則運算
ZeroJudge python解答:a020. 身分證檢驗
ZeroJudge python解答:a021. 大數運算
ZeroJudge python解答:a022. 迴文
ZeroJudge python解答:a024. 最大公因數(GCD)
ZeroJudge python解答:a034. 二進位制轉換
ZeroJudge python解答:a038. 數字翻轉
ZeroJudge python解答:a040. 阿姆斯壯數
ZeroJudge python解答:a042. 平面圓形切割
ZeroJudge python解答:a044. 空間切割
ZeroJudge python解答:a053. Sagit's 計分程式
ZeroJudge python解答:a054. 電話客服中心
ZeroJudge python解答:a058. MOD3
ZeroJudge python解答:a059. 完全平方
ZeroJudge python解答:a065. 提款卡密碼
ZeroJudge python解答:a104. 排序
ZeroJudge python解答:a121. 質數又來囉
ZeroJudge python解答:a148. You Cannot Pass?!
ZeroJudge python解答:a149. 乘乘樂
ZeroJudge python解答:a215. 明明愛數數
ZeroJudge python解答:a216. 數數愛明明
ZeroJudge python解答:a224. 明明愛明明
ZeroJudge python解答:a225. 明明愛排列
ZeroJudge python解答:a244. 新手訓練 ~ for + if
ZeroJudge python解答:a248. 新手訓練 ~ 陣列應用
ZeroJudge python解答:a263. 日期差幾天
ZeroJudge  python解答:a694. 吞食天地二
ZeroJudge python解答:a738. 最大公约数
 





2023年6月26日 星期一

ZeroJudge python解答:a010. 因數分解

 
我的第三次解答:
num = int(input())
k = dict()
while num != 1:
    for i in range(2,num+1):
        if num%i == 0:
            if i in k.keys():
                k[i] = k[i] + 1
            else:
                k[i] = 1
            num = num//i
            break
Str = ''    
for i in k.keys():
    if k[i] != 1:
        Str = Str+' * '+str(i)+'^'+str(k[i])
    else:
        Str = Str+' * '+str(i)
print(Str.lstrip(' * '))
檢測結果:

我的第二次解答:
factors = []
PrimeSet = set()
CompositeSet = set()
Str = ''
InputNumber = int(input())
# 因數集合
for i in range(2,InputNumber+1):
    if InputNumber%i == 0:
        factors.append(i)
        for j in range(2,i):
            if i%j == 0:
                CompositeSet.add(i)
PrimeSet = set(factors) - CompositeSet

for i in sorted(PrimeSet):
    k = 0  
    while InputNumber%i == 0:
        k = k + 1
        InputNumber = InputNumber//i
    if k == 1:
        Str = Str+' * '+str(i)
    else:
        Str = Str+' * '+str(i)+'^'+str(k)

print(Str.lstrip(' * '))
檢測結果:



我的第一次解答:
factors = []
PrimeSet = set()
CompositeSet = set()
InputNumber = int(input())
Power = dict()
# 因數集合
for i in range(1,InputNumber+1):
    if InputNumber%i == 0:
        factors.append(i)
# 找因數集合內的合數集合
for i in factors:
    if i > 1:
        for j in range(2,i):
            if i%j == 0:
                CompositeSet.add(i)

# 質數集合
PrimeSet = set(factors) - {1} - CompositeSet

# 質數集合,找各質數的次方  
for i in sorted(PrimeSet):
    quotient = InputNumber//i
    k = 1
    while quotient%i == 0:
        k=k+1
        quotient = quotient//i
    Power[i] = k

# 調整輸出
Str=''
for i in Power.keys():
    j = Power[i]
    if j == 1:
        Str = Str+' * '+str(i)
    else:
        Str = Str+' * '+str(i)+'^'+str(j)
# 輸出
print(Str.lstrip(' * '))
檢測結果:



資料來源:
1.高中生解題系統
2.

ZeroJudge解題
ZeroJudge  python解答:a001. 哈囉

ZeroJudge python解答:a004. 文文的求婚
ZeroJudge python解答:a005. Eva 的回家作業
ZeroJudge python解答:a006. 一元二次方程式
ZeroJudge python解答:a009. 解碼器
ZeroJudge python解答:a010. 因數分解
ZeroJudge python解答:a015. 矩陣的翻轉
ZeroJudge python解答:a017. 五則運算
ZeroJudge python解答:a020. 身分證檢驗
ZeroJudge python解答:a021. 大數運算
ZeroJudge python解答:a022. 迴文
ZeroJudge python解答:a024. 最大公因數(GCD)
ZeroJudge python解答:a034. 二進位制轉換
ZeroJudge python解答:a038. 數字翻轉
ZeroJudge python解答:a040. 阿姆斯壯數
ZeroJudge python解答:a042. 平面圓形切割
ZeroJudge python解答:a044. 空間切割
ZeroJudge python解答:a053. Sagit's 計分程式
ZeroJudge python解答:a054. 電話客服中心
ZeroJudge python解答:a058. MOD3
ZeroJudge python解答:a059. 完全平方
ZeroJudge python解答:a065. 提款卡密碼
ZeroJudge python解答:a104. 排序
ZeroJudge python解答:a121. 質數又來囉
ZeroJudge python解答:a148. You Cannot Pass?!
ZeroJudge python解答:a149. 乘乘樂
ZeroJudge python解答:a215. 明明愛數數
ZeroJudge python解答:a216. 數數愛明明
ZeroJudge python解答:a224. 明明愛明明
ZeroJudge python解答:a225. 明明愛排列
ZeroJudge python解答:a244. 新手訓練 ~ for + if
ZeroJudge python解答:a248. 新手訓練 ~ 陣列應用
ZeroJudge python解答:a263. 日期差幾天
ZeroJudge  python解答:a694. 吞食天地二
ZeroJudge python解答:a738. 最大公约数
 





ZeroJudge python解答:a009. 解碼器

問題:由於題目中需要用到ASCII,於是找大神。我們可以得到資料來源2.ASCII。如下表:
根據題目中的提示,將輸入輸出一起看。得到下表:
發現k=7
接下來,依據資料來源3.Python ASCII碼與字符相互轉換。利用ord() 與 chr() 來做轉換。

我的解答為
c = input()
for i in c:
    print(chr(ord(i)-7),end='')

資料來源:
1.高中生解題系統
2.

ZeroJudge解題
ZeroJudge  python解答:a001. 哈囉

ZeroJudge python解答:a004. 文文的求婚
ZeroJudge python解答:a005. Eva 的回家作業
ZeroJudge python解答:a006. 一元二次方程式
ZeroJudge python解答:a009. 解碼器
ZeroJudge python解答:a010. 因數分解
ZeroJudge python解答:a015. 矩陣的翻轉
ZeroJudge python解答:a017. 五則運算
ZeroJudge python解答:a020. 身分證檢驗
ZeroJudge python解答:a021. 大數運算
ZeroJudge python解答:a022. 迴文
ZeroJudge python解答:a024. 最大公因數(GCD)
ZeroJudge python解答:a034. 二進位制轉換
ZeroJudge python解答:a038. 數字翻轉
ZeroJudge python解答:a040. 阿姆斯壯數
ZeroJudge python解答:a042. 平面圓形切割
ZeroJudge python解答:a044. 空間切割
ZeroJudge python解答:a053. Sagit's 計分程式
ZeroJudge python解答:a054. 電話客服中心
ZeroJudge python解答:a058. MOD3
ZeroJudge python解答:a059. 完全平方
ZeroJudge python解答:a065. 提款卡密碼
ZeroJudge python解答:a104. 排序
ZeroJudge python解答:a121. 質數又來囉
ZeroJudge python解答:a148. You Cannot Pass?!
ZeroJudge python解答:a149. 乘乘樂
ZeroJudge python解答:a215. 明明愛數數
ZeroJudge python解答:a216. 數數愛明明
ZeroJudge python解答:a224. 明明愛明明
ZeroJudge python解答:a225. 明明愛排列
ZeroJudge python解答:a244. 新手訓練 ~ for + if
ZeroJudge python解答:a248. 新手訓練 ~ 陣列應用
ZeroJudge python解答:a263. 日期差幾天
ZeroJudge  python解答:a694. 吞食天地二
ZeroJudge python解答:a738. 最大公约数
 





ZeroJudge python解答:a271. 彩色蘿蔔

  a271. 彩色蘿蔔 我的解法: 這題的重點只有兩個: 每天早上先扣中毒效果,再吃蘿蔔 中毒可累加,而且吃到黑蘿蔔當天不扣毒,從隔天開始扣 t = int ( input ()) for i in range ( t ):     x , y , z ,...