2018春招-今日頭條筆試題-第三題(python)

來源:互聯網
上載者:User

標籤:pen   style   blog   儲存   pre   c++   col   input   append   

題目描述:2018春招-今日頭條筆試題5題(後附大佬答案-c++版)

解題思路:

本題的做法最重要的應該是如何拼出‘1234567890’,對於輸入表達試獲得對應的結果利用python內建函數eval()即可以實現。利用5個字串來表達‘1234567890’,如下(為了好看,裡面加了tab空格符)

‘66666  ....6  66666  66666  6...6  66666  66666  66666  66666  66666‘
‘6...6  ....6  ....6  ....6  6...6  6....  6....  ....6  6...6  6...6‘
‘6...6  ....6  66666  66666  66666  66666  66666  ....6  66666  66666‘
‘6...6  ....6  6....  ....6  ....6  ....6  6...6  ....6  6...6  ....6‘
‘66666  ....6  66666  66666  ....6  66666  66666  ....6  66666  66666‘
#-*- coding:utf-8 -*-list_s=[ ‘66666....666666666666...66666666666666666666666666‘,         ‘6...6....6....6....66...66....6........66...66...6‘,         ‘6...6....66666666666666666666666666....66666666666‘,         ‘6...6....66........6....6....66...6....66...6....6‘,         ‘66666....66666666666....66666666666....66666666666‘]n = int(input())list_n=[]#儲存輸入的運算式for a in range(0,n):    a=raw_input()    list_n.append(a)for b in list_n:    s = eval(b)    #將數字轉化為list    s=[int(i) for i in str(s)]    for i in range(0,5):        #將每個數位一行存在一個數組        string=[]        for j in s:            string.append(list_s[i][j * 5:j * 5 + 5])        #以‘..’輸出每一行        print ‘..‘.join(string)

 

 

2018春招-今日頭條筆試題-第三題(python)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.