iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 8
1
自我挑戰組

程式設計師大冒險系列 第 8

8/150_第八天新的里程碑

  • 分享至 

  • twitterImage
  •  

鐵人賽心得

成功撐過第一週,透過參加鐵人賽,建立我穩定刷題習慣。


個人狀態

https://ithelp.ithome.com.tw/upload/images/20181008/20091910dvk6YnlP5d.jpg


本週目標與修正

目前適應一週一題強度,接下來挑戰一天兩題。
本週五預計參加OKWORK內湖科技園區中型徵才活動
以PHP語言製作單機版作品集展示網頁

  • UVa(1/14)
    -參加面試(0/1)
    -展示網頁(0/1)

490 Rotating Sentences

解題思路

文章的轉置,想像把平躺的長方形,扶正成站立的長方形。

input

測資採用(uDebug資料)[https://www.udebug.com/UVa/490]
https://ithelp.ithome.com.tw/upload/images/20181008/200919109rU3tmzrnG.jpg
怕會有灌水嫌疑,這邊就貼圖片示意,右下角有一鍵複製。

import sys
#讀取測資
def inp():
    ar=[]
    sin=sys.stdin.readline()
    while(sin!=""):
        sin=sin.replace("\r","").replace("\n","")
        ar.append(sin)
        sin=sys.stdin.readline()
    print(ar)#測試(測資是否正確讀取)
    transpose(ar)

https://ithelp.ithome.com.tw/upload/images/20181008/20091910KYHqp5GCTk.jpg
測試結果很長,這邊只擷取部分

    
#轉置函數
def transpose(ar):
    endst=max(len(l)for l in ar)#文章高度(搜尋最長的那一行)
    for j in range(endst):#文章高度
        #print(endst,i,j)
        print(j,end="")#測試(輸出每一列)
        for i in range(len(ar)-1,-1,-1):#迴圈(文章總行數)
            if(j<len(ar[i])):#請問長度夠輸出嗎?
                print(ar[i][j],end="")#輸出字元
            else:
                print(" ",end="")#輸出空白
        print("")
    
inp()

https://ithelp.ithome.com.tw/upload/images/20181008/20091910a66FYZ3vpR.jpghttps://ithelp.ithome.com.tw/upload/images/20181008/20091910BH9277CcZG.jpg
總共有一百列,列數很長這邊只貼頭跟尾,尾的地方解比較久。


這次解題過程進行改版,希望增加文章易讀性。
感謝撥冗閱讀,有需要改進的地方,歡迎批評指教。


上一篇
7/150_11332 - Summing Digits、10252 - Common Permutation(Python)
下一篇
9/150_字串題型並不難272 - TEX Quotes
系列文
程式設計師大冒險115
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言