程式碼出現第 9 天:磁碟碎片
今天的解決方案只是用 Python 完成的,老實說,我發現很難找到時間用 Python 和 C# 編寫以及撰寫文章,所以選擇繼續使用其中之一。
第 1 部分
這相當簡單,要求是將輸入轉換為 id 和空格,其中奇數索引是 id,偶數索引是空格 (.) 並重複 x 次,與輸入中的數字相關,例如;
1234 =>
1 =>; 1x id --> 0
2=> 2x 空 --> ..
3=> 3x id --> 111
4=> 4x 空 --> ....
整體線=> 0..111....
然後我們被要求將最右邊的元素移到最左邊的空白區域。
即移動 1 ->第一個 (.),我們使用兩個循環來完成此操作,一個從後面開始 ->前面,另一個前面->後部。
當我們找到一個Id時,我們從前面移動到找到第一個空位,然後交換這些點,繼續下去,直到右邊的所有數字都移動到左邊的空位。
只要右邊的索引,總是比左邊的索引大,或是中間沒有相遇就一直走。
第2部分
現在,我們不只是找到最左邊的空白空間,而是必須嘗試找到一個最左邊的空白空間,它可以容納整個文件(id),例如,如果我們的fileId 為9999,我們需要4空的空間在一起,如果它不會,我們將其移動到下一個空的空間。如果沒有空格,我們將移動到下一個 fileId。
[劇透] ->解可以在 GitHub 找到
一如既往,您可以在 Twitter 上聯繫並關注
以上是程式碼的出現 - DayDisk Fragmenter (Python)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Python是解釋型語言,但也包含編譯過程。 1)Python代碼先編譯成字節碼。 2)字節碼由Python虛擬機解釋執行。 3)這種混合機制使Python既靈活又高效,但執行速度不如完全編譯型語言。

UseeAforloopWheniteratingOveraseQuenceOrforAspecificnumberoftimes; useAwhiLeLoopWhenconTinuingUntilAcIntiment.forloopsareIdealForkNownsences,而WhileLeleLeleLeleLeleLoopSituationSituationsItuationsItuationSuationSituationswithUndEtermentersitations。

pythonloopscanleadtoerrorslikeinfiniteloops,modifyingListsDuringteritation,逐個偏置,零indexingissues,andnestedloopineflinefficiencies

forloopsareadvantageousforknowniterations and sequests,供應模擬性和可讀性;而LileLoopSareIdealFordyNamicConcitionSandunknowniterations,提供ControloperRoverTermination.1)forloopsareperfectForeTectForeTerToratingOrtratingRiteratingOrtratingRitterlistlistslists,callings conspass,calplace,cal,ofstrings ofstrings,orstrings,orstrings,orstrings ofcces

pythonisehybridmodeLofCompilation和interpretation:1)thepythoninterpretercompilesourcecececodeintoplatform- interpententbybytecode.2)thepythonvirtualmachine(pvm)thenexecutecutestestestestestesthisbytecode,ballancingEaseofuseEfuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允許fordingfordforderynamictynamictymictymictymictyandrapiddefupment,儘管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知識之際,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations則youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版
好用的JavaScript開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能