IN3. Strings and Lists

更新於 發佈於 閱讀時間約 2 分鐘

題目連結


給一長串的字串資料,然後a, b, c, d 4個數字

需切出字串[a~b]、字串[c~d]的位置,連接後印出來

(須包含字串[b]、字串[d]的位置)


輸入

HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntputHumptyDumptyinhisplaceagain.
22 27 97 102

輸出

Humpty Dumpty


程式碼:

s = "HumptyDumptysatonawallHumptyDumptyhadagreatfallAlltheKingshorsesandalltheKingsmenCouldntputHumptyDumptyinhisplaceagain"

a, b, c, d = 22, 27, 97, 102
# a, b, c, d = map(int, input().split()) # 開啟手動輸入數字

print(s[a:b+1], s[c:d+1])
留言
avatar-img
留言分享你的想法!
avatar-img
生物資訊實驗室
0會員
17內容數
這裡存放著滿滿的大平台!Rosalind 生物資訊解題平台的學習過程! 📢 適合對象: ✅ 想學習生物資訊的程式新手 ✅ 對Python程式有基礎,想挑戰 Rosalind 題目的解題者 ✅ 對DNA、蛋白質、基因組數據分析有興趣的人
生物資訊實驗室的其他內容
2025/03/20
題目:https://rosalind.info/problems/ini6/ 從這題開始有一點點難度了 計算每個字詞出現的次數,區分大小寫(Python Dict 預設就是大小寫敏感) 首先將輸入字串,按照空白字元做切割,得到一個陣列 ['We', 'tried', 'list',
2025/03/20
題目:https://rosalind.info/problems/ini6/ 從這題開始有一點點難度了 計算每個字詞出現的次數,區分大小寫(Python Dict 預設就是大小寫敏感) 首先將輸入字串,按照空白字元做切割,得到一個陣列 ['We', 'tried', 'list',
2025/03/19
題目:https://rosalind.info/problems/ini5/ 讀入一個充滿文字的檔案 按照1-based 索引取出偶數行(第2、4、6... 行) with open("IN5.txt", "r", encoding="utf-8") as file: lines
2025/03/19
題目:https://rosalind.info/problems/ini5/ 讀入一個充滿文字的檔案 按照1-based 索引取出偶數行(第2、4、6... 行) with open("IN5.txt", "r", encoding="utf-8") as file: lines
2025/03/18
計算所有在a~b之間的奇數數字 python沒有內建 isOdd()函式,所以只能寫ifㄍ判斷奇數、偶數 a, b = 100, 200 s = 0 for i in range(a, b+1): if i % 2 == 1: s += i print(s)
2025/03/18
計算所有在a~b之間的奇數數字 python沒有內建 isOdd()函式,所以只能寫ifㄍ判斷奇數、偶數 a, b = 100, 200 s = 0 for i in range(a, b+1): if i % 2 == 1: s += i print(s)
看更多