武兵 7933 字 5個月前

ICON語言

(5 / 7)
⚡ 登入後報錯可獲 3天VIP 免廣告——立即登入

ngthelistsofvaluesinbrackets.Anexampleis

car1:=[\"buick\",\"skylark\",1978,2450]

inwhichthelistcar1hasfourvalues,twoofwhicharestringsandtwoofwhichareintegers.Notethatthevaluesinalistneednotallbeofthesametype.Infact,anykindofvaluecanoccurinalist--evenanotherlist,asin

inventory:=[car1,car2,car3,car4]

Listsalsocanbecreatedby

L:=list(i,x)

whichcreatesalistofivalues,eachofwhichhasthevaluex.

Thevaluesinalistcanbereferencedbyposition.Thus,

car1:=2400

changesthelastvalueincar1to2400.Areferencethatisoutoftherangeofthelistfails.Forexample,

write(car1[5])

fails.

ThevaluesinalistLaregeneratedby!L.Thus

everywrite(!L)

writesallthevaluesinL.

Listscanbemanipulatedlikestacksandqueues.Thefunctionpush(L,x)addsthevalueofxtotheleftendofthelistL,automaticallyincreasingthesizeofLbyone.Similarly,pop(L)removestheleftmostvaluefromL,automaticallydecreasingthesizeofLbyone,andproducestheremovedvalue.

4.2Sets

Asetisacollectionofvalues.Anemptysetiscreatedbyset().Alternatively,set(L)producesasetwiththevaluesinthelistL.Forexample,

S:=set([1,\"abc\",[]])

assignstoSasetthatcontainstheinteger1,thestring\"abc\",andanemptylist.

Thesetoperationsofunion,intersection,anddifferenceareprovided.Thefunctionmember(S,x)succeedsifxisamemberofthesetSbutfailsotherwise.Thefunctioninsert(S,x)addsxtothesetS,whiledelete(S,x)removesxfromS.Avalueonlycanoccuronceinaset,soinsert(S,x)hasnoeffectifxisalreadyinS.!SgeneratesthemembersofS.

Asimpleexampleoftheuseofsetsisgivenbythefollowingsegmentof,whichlistsallthedifferentwordsthatappearintheinputfile:

words:=set()

whileline:=read()do

od))srettel&(otpu(batelihw?enil

w t . p o o問訪請容內說小多更

)))srettel&(ynam(bat,sdrow(tresni

)sdrow!(etirwyreve

selbaT3.4

.stsilniseulavotsseccalanoitisopehthtiwtsartnocnisseccaevitaicossafomrofaedivorpselbat,suhT.yllacitamotuapudekoolebnacyekynarofeulavehtdna,epytynafoebyameulavgnidnopserrocstidnayekehT.eulavgnidnopserrocadnayekafostsisnochcihwfohcaesriapfosteseraselbaT

sahcusnoisserpxenaybdetaercsielbatA

)0(elbat=:slobmys

sahcus,yekynaybdecnereferebnacslobmys,yltneuqesbuS.eulavrehtonadengissatoneratahtsyekrofdesusieulavtluafedehT.0eulavtluafedehthtiwelbataslobmysotsngissahcihw

1=:]"\ereht"\[slobmys

.slobmysni"\ereht"\yekehtot1eulavehtsngissahcihw

udorptnemgesmargorpgniwollofeht,elpmaxeroF.deddaerasyekwensayllacitamotuaworgselbaT


✅ 付款功能已修復,現在可以正常購買了 — 支援信用卡 · Apple Pay · Google Pay · WebATM · ATM 轉帳
😤 廣告總在最入戲的時候跳出來?
月付 $5 USD,升級 VIP 後全站所有頁面廣告立即全關——
不是只有這本書,是整個 oop.tw 每一頁、每一章,從此一路讀到底不被打斷。 $5 USD ≈ 一杯珍奶的錢,換一整個月零廣告清爽閱讀 · 隨時可取消
✅ 全站廣告全關 ✅ 工口專區全本解鎖 ✅ 月卡 $5 USD · 季卡 $13 USD · 年卡 $45 USD
⭐ 登入 / 免費註冊後升級
加我 LINE 好友,分享好書不錯過
第一時間獲得新書推薦、書單更新通知
立即加入
上一頁 書頁/目錄
/ 7 頁
下一頁
為本書評分(每位讀者可評一次,提交後無法修改)
發表評論
以 匿名讀者 身份發表
讀者評論