Project1.pdf

‫ﺑﻪ ﻧﺎﻡ ﺧﺪﺍﻭﻧﺪ ﻣﻬﺮﺑﺎﻥ‬
‫درس داده ﺳﺎﺧﺘﺎرﻫﺎ و اﻟﮕﻮرﻳﺘﻢ ﻫﺎ‬
‫ﭘﺮوژه ي ﺷﻤﺎره ﻳﻚ‬
‫ﻣﻮﻋﺪ ﺗﺤﻮﻳﻞ‪1389/9/3 :‬‬
‫ﻓﺎﻳﻞ ﻫﺎﯼ ﻻﺯﻡ ﺑﺮﺍﯼ ﺍﺟﺮﺍﯼ ﺑﺮﻧﺎﻣﻪ ﯼ ﻣﺮﺑﻮﻁ ﺑﻪ ﻫﺮ ﺳﻮﺍﻝ ﺭﺍ ﺩﺭ ﭘﻮﺷﻪ ﺍﯼ ﻣﺠﺰﺍ ﻗﺮﺍﺭ ﺩﻫﻴﺪ‪ ،‬ﺍﻳﻦ ﭘﻮﺷﻪ ﻫﺎ ﺭﺍ ﺩﺭ ﻳﮏ‬
‫ﭘﻮﺷﻪ ﺑﺎ ﻧﺎﻡ ‪ stdID_Project1‬ﮐﻪ ﺑﻪ ﺟﺎﯼ ‪ stdID‬ﺷﻤﺎﺭﻩ ﺩﺍﻧﺸﺠﻮﻳﯽ ﺧﻮﺩ ﺭﺍ ﻗﺮﺍﺭ ﻣﯽ ﺩﻫﻴﺪ ﺑﮕﺬﺍﺭﻳﺪ ﻭ ﺍﻳﻦ ﭘﻮﺷﻪ‬
‫ﺭﺍ ﺗﺎ ﻗﺒﻞ ﺍﺯ ‪ ۱۲‬ﻧﻴﻤﻪ ﺷﺐ ﺳﻮﻡ ﺁﺫﺭ ﺑﻪ ﺁﺩﺭﺱ ‪ ds891hw@gmail.com‬ﺍﺭﺳﺎﻝ ﮐﻨﻴﺪ‪) .‬ﻋﻨﻮﺍﻥ ﺍﻳﻤﻴﻞ ﻫﻤﺎﻥ ﻧﺎﻡ‬
‫ﭘﻮﺷﻪ ﯼ ﺿﻤﻴﻤﻪ ﺷﺪﻩ ﺑﺎﺷﺪ‪(.‬‬
‫ﺍﮔﺮ ﻫﺮﮔﻮﻧﻪ ﺍﺑﻬﺎﻡ ﻳﺎ ﭘﺮﺳﺸﯽ ﺩﺭ ﻣﻮﺭﺩ ﺳﻮﺍﻻﺕ ﺩﺍﺷﺘﻴﺪ ﺑﻪ ﺁﺩﺭﺱ ‪ ds891hw@gmail.com‬ﺍﻳﻤﻴﻞ ﺑﺰﻧﻴﺪ‪.‬‬
‫ﺳﻮﺍﻝ ﺍﻭﻝ‪ :‬ﺩﺍﻳﺮﻩ ﯼ ﭼﺮﺧﺎﻥ‬
‫ﺗﻌﺮﻳﻒ ﻣﺴﺎﻟﻪ‬
‫ﻫﺪﻑ ﺍﻳﻦ ﭘﺮﻭﮊﻩ ﭘﻴﺎﺩﻩﺳﺎﺯﯼ ﺩﺍﺩﻩ ﺳﺎﺧﺘﺎﺭﯼ ﻣﻨﺎﺳﺐ ﺑﺮﺍﯼ ﻧﮕﻪﺩﺍﺭﯼ ﺍﻋﺪﺍﺩ‪ ‬ﺭﻭﯼ ﻳﮏ ﺩﺍﻳﺮﻩ ﻭ ﺍﺟﺮﺍﯼ ﺩﺳﺘﻮﺭﺍﺕ‬
‫ﺧﻮﺍﺳﺘﻪ ﺷﺪﻩ ﺑﺮ ﺭﻭﯼ ﺁﻥﻫﺎ‪ ،‬ﺑﻪ ﮐﻤﮏ ﻳﮏ ﻟﻴﻨﮏ ﻟﻴﺴﺖ ﺩﻭﻃﺮﻓﻪ ﺍﺳﺖ‪.‬‬
‫ﺩﺭ ﺍﺑﺘﺪﺍ ﺩﻧﺒﺎﻟﻪﺍﯼ ‪ n‬ﺗﺎﻳﯽ ﺍﺯ ﺍﻋﺪﺍﺩ ﻫﻤﭽﻮﻥ ‪ v1, v2, … , vn‬ﺩﻭﺭ ﻳﮏ ﺩﺍﻳﺮﻩ ﻗﺮﺍﺭ ﮔﺮﻓﺘﻪﺍﻧﺪ ﻭ ﺍﺷﺎﺭﻩﮔﺮﯼ ﺑﻪ ‪ v1‬ﺍﺷﺎﺭﻩ‬
‫ﻣﯽﮐﻨﺪ‪ .‬ﺍﺯ ﺍﻳﻦ ﺑﻪ ﺑﻌﺪ ﺑﻪ ﺟﺎﻳﮕﺎﻫﯽ ﮐﻪ ﺍﺷﺎﺭﻩﮔﺮ ﺑﻪ ﺁﻥ ﺍﺷﺎﺭﻩ ﻣﯽﮐﻨﺪ‪" ،‬ﺩﺳﺘﻪ‪ "١‬ﻣﯽﮔﻮﻳﻴﻢ‪.‬‬
‫ﺣﺎﻝ ﺩﻧﺒﺎﻟﻪﺍﯼ ﺍﺯ ﺩﺳﺘﻮﺭﺍﺕ ﺑﻪ ﻋﻨﻮﺍﻥ ﻭﺭﻭﺩﯼ ﮔﺮﻓﺘﻪ ﻣﯽﺷﻮﻧﺪ ﻭ ﺑﻪ ﺗﺮﺗﻴﺐ ﺑﺮ ﺭﻭﯼ ﺍﻋﺪﺍﺩ ﺩﻭﺭ ﺩﺍﻳﺮﻩ ﺍﻋﻤﺎﻝ ﻣﯽﺷﻮﻧﺪ‪.‬‬
‫ﺩﺳﺘﻮﺭﺍﺕ ‪ ۳‬ﻧﻮﻉ ﻫﺴﺘﻨﺪ‪:‬‬
‫‪ ‬‬
‫‪ handle ‬‬
‫‪1‬‬
‫‪ ‬ﺣﺬﻑ ﻋﺪﺩ‪ ٢‬‬
‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﻳﮏ ﻋﺪﺩ ﺑﻪ ﻋﻨﻮﺍﻥ ﺁﺭﮔﻮﻣﺎﻥ ﻭﺭﻭﺩﯼ ﻣﯽﮔﻴﺮﺩ )ﮐﻪ ﺁﻥ ﺭﺍ ‪ a‬ﻣﯽﻧﺎﻣﻴﻢ(‪ .‬ﺑﺎ ﺩﻳﺪﻥ ﺍﻳﻦ ﺩﺳﺘﻮﺭ‬
‫ﺑﺼﻮﺭﺕ ﺳﺎﻋﺘﮕﺮﺩ ‪ a‬ﺧﺎﻧﻪ ﺟﻠﻮ ﻣﯽﺭﻭﻳﻢ‪ ،‬ﺩﺳﺘﻪ ﺭﺍ ﺑﺮﺍﺑﺮ ﺧﺎﻧﻪ ﺑﻌﺪ )ﻳﻌﻨﯽ ‪ a+1‬ﺍﻣﻴﻦ ﺟﺎﻳﮕﺎﻩ ﭘﺲ ﺍﺯ ﺩﺳﺘﻪ(‬
‫ﻗﺮﺍﺭ ﺩﺍﺩﻩ ﻭ ﺧﺎﻧﻪﯼ ‪ a‬ﺍﻡ ﺭﺍ ﺣﺬﻑ ﻣﯽﮐﻨﻴﻢ‪ .‬ﺑﻄﻮﺭ ﻣﺜﺎﻝ ﺍﮔﺮ ﺩﻧﺒﺎﻟﻪﯼ ﺍﻋﺪﺍﺩ ‪ 5, ‐2, 3, 4, 0 ‬ﺑﻮﺩﻩ )ﺍﻳﻦ‬
‫ﺍﻋﺪﺍﺩ ﺍﺯ ﺳﻤﺖ ﭼﭗ ﺑﺼﻮﺭﺕ ﺳﺎﻋﺘﮕﺮﺩ ﺭﻭﯼ ﺩﺍﻳﺮﻩ ﻗﺮﺍﺭ ﺩﺍﺭﻧﺪ( ﻭ ﺩﺳﺘﻪ ﺩﺭﺟﺎﻳﮕﺎﻩ ﺳﻮﻡ )ﺧﺎﻧﻪﯼ ﻣﺤﺘﻮﯼ ‪(3‬‬
‫ﺑﺎﺷـﺪ‪ ،‬ﺩﺭ ﺻﻮﺭﺕ ﺩﻳﺪﻥ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺎ ﺁﺭﮔﻮﻣﺎﻥ ‪ ،2‬ﭘﺲ ﺍﺯ ﺣﺬﻑ ﺧﺎﻧﻪﯼ ﻣـﺤﺘﻮﯼ ‪ ،0‬ﺩﻧﺒﺎﻟﻪ ﺑـﺼﻮﺭﺕ ‪ ‬‬
‫‪ 5, ‐2, 3, 4‬ﺩﺭﺁﻣﺪﻩ ﻭ ﺩﺳﺘﻪ ﺑﺮ ﺭﻭﯼ ﺧﺎﻧﻪﯼ ﻣﺤﺘﻮﯼ ‪ 5‬ﻗﺮﺍﺭ ﻣﯽﮔﻴﺮﺩ‪.‬‬
‫ﺍﮔﺮ ‪ a‬ﻋﺪﺩﯼ ﻣﻨﻔﯽ ﺑﺎﺷﺪ‪ ،‬ﺑﻪ ﺍﻧﺪﺍﺯﻩﯼ ‪ –a‬ﺑﺼﻮﺭﺕ ﭘﺎﺩﺳﺎﻋﺘﮕﺮﺩ ﺣﺮﮐﺖ ﻣﯽﮐﻨﻴﻢ‪.‬ﺩﺭ ﻣﺜﺎﻝ ﻗﺒﻞ ﺍﮔﺮ ﺁﺭﮔﻮﻣﺎﻥ‬
‫ﻭﺭﻭﺩﯼ ﻋﺪﺩ ‪ ‐2‬ﺑﺎﺷـﺪ‪ ،‬ﺑﻌﺪ ﺍﺯ ﺍﺟﺮﺍﯼ ﺩﺳﺘـﻮﺭ ﺧﺎﻧﻪﯼ ﻣـﺤﺘﻮﯼ ‪ 5‬ﺣـﺬﻑ ﻣـﯽﺷﻮﺩ ﻭ ﺩﻧﺒﺎﻟﻪ ﺑـﺼﻮﺭﺕ ‪ ‬‬
‫‪ ‐2, 3, 4, 0‬ﺩﺭﺁﻣﺪﻩ ﻭ ﺩﺳﺘﻪ ﺑﺮ ﺭﻭﯼ ﺧﺎﻧﻪﯼ ﻣﺤﺘﻮﯼ ‪ ‐2‬ﻗﺮﺍﺭ ﺧﻮﺍﻫﺪ ﺩﺍﺷﺖ‪.‬‬
‫‪ ‬ﺩﺭﺝ ﻋﺪﺩ‪ ٣‬‬
‫ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺩﻭ ﻋﺪﺩ ﺑﻪ ﻋﻨﻮﺍﻥ ﺁﺭﮔﻮﻣﺎﻥ ﺧﻮﺩ ﻣﯽﮔﻴﺮﺩ )ﮐﻪ ﺁﺭﮔﻮﻣﺎﻥ ﺍﻭﻝ ﺭﺍ ‪ a‬ﻭ ﺁﺭﮔﻮﻣﺎﻥ ﺩﻭﻡ ﺭﺍ ‪ b‬ﻣﯽ‬
‫ﻧﺎﻣﻴﻢ(‪ .‬ﺑﺎ ﺩﻳﺪﻥ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺼﻮﺭﺕ ﺳﺎﻋﺘﮕﺮﺩ ‪ a‬ﺧﺎﻧﻪ ﺟﻠﻮ ﻣﯽﺭﻭﻳﻢ ﻭ ﺑﻌﺪ ﺍﺯ ﺍﻳﻦ ﺧﺎﻧﻪ )ﻳﻌﻨﯽ ﺑﻴﻦ ‪ a‬ﺍﻣﻴﻦ ﻭ‬
‫‪ a+1‬ﺍﻣﻴﻦ ﺧﺎﻧﻪ ﺑﻌﺪ ﺍﺯ ﺩﺳﺘﻪ( ﻳﮏ ﺟﺎﻳﮕﺎﻩ ﺟﺪﻳﺪ ﺍﻳﺠﺎﺩ ﻣﯽﮐﻨﻴﻢ ﻭ ﻋﺪﺩ ﺁﻥ ﺧﺎﻧﻪ ﺭﺍ ﺑﺮﺍﺑﺮ ‪ b‬ﻗﺮﺍﺭ ﻣﯽﺩﻫﻴﻢ‪.‬‬
‫ﻫﻤﭽﻨﻴﻦ ﺩﺳﺘﻪ ﺭﺍ ﺑﺮ ﺭﻭﯼ ﺟﺎﻳﮕﺎﻩ ﺟﺪﻳﺪ ﻗﺮﺍﺭ ﻣﯽﺩﻫﻴﻢ‪ .‬ﺑﻄﻮﺭ ﻣﺜﺎﻝ ﺍﮔﺮ ﺩﻧﺒﺎﻟﻪﯼ ﺍﻋﺪﺍﺩ ‪1, 4, ‐2, 4, 0‬‬
‫ﺑﻮﺩﻩ ﻭ ﺩﺳﺘﻪ ﺩﺭ ﺟﺎﻳﮕﺎﻩ ﺳﻮﻡ )ﺧﺎﻧﻪﯼ ﻣﺤﺘﻮﯼ ‪ (‐2‬ﺑﺎﺷﺪ‪ ،‬ﺑﺎ ﺩﻳﺪﻥ ﺍﻳﻦ ﺩﺳﺘﻮﺭ ﺑﺎ ﺁﺭﮔﻮﻣﺎﻥﻫﺎﯼ )‪ (3, 5‬‬
‫)‪ 3‬ﺁﺭﮔﻮﻣﺎﻥ ﺍﻭﻝ ﻭ ‪ 5‬ﺁﺭﮔﻮﻣﺎﻥ ﺩﻭﻡ ﺍﺳﺖ(‪ ،‬ﭘﺲ ﺍﺯ ﺩﺭﺝ ‪ 5‬ﺑﻴﻦ ‪ 1‬ﻭ ‪ ،4‬ﺩﻧﺒﺎﻟﻪ ﺑﺼﻮﺭﺕ ‪1, 5, 4, ‐2, 4, 0‬‬
‫ﺩﺭﺁﻣﺪﻩ ﻭ ﺩﺳﺘﻪ ﺑﺮ ﺭﻭﯼ ﺧﺎﻧﻪﯼ ﻣﺤﺘﻮﯼ ‪ 5‬ﻗﺮﺍﺭ ﻣﯽﮔﻴﺮﺩ‪.‬‬
‫‪ ‬ﭼﺎﭖ‪ ٤‬‬
‫ﺩﺭ ﺧﺮﻭﺟﯽ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ ﺗﻨﻬﺎ ﻋﺪﺩ ﺟﺎﻳﮕﺎﻩ ﺩﺳﺘﻪ ﺭﺍ ﭼﺎﭖ ﻣﯽﮐﻨﺪ‪.‬‬
‫‪ ‬‬
‫‪ ‬‬
‫‪2‬‬
‫‪ delete ‬‬
‫‪ insert ‬‬
‫‪4‬‬
‫‪ print ‬‬
‫‪3‬‬
‫ﻭﺭﻭﺩﯼ‬
‫ﻭﺭﻭﺩﯼ ﺍﺯ ﻭﺭﻭﺩﯼ ﺍﺳﺘﺎﻧﺪﺍﺭﺩ ﺧﻮﺍﻧﺪﻩ ﻣﯽﺷﻮﺩ‪ .‬ﺍﻭﻟﻴﻦ ﺧﻂ ﻭﺭﻭﺩﯼ ‪ ،n‬ﺗﻌﺪﺍﺩ ﺍﻭﻟﻴﻪ ﺍﻋﺪﺍﺩ ﺁﻣﺪﻩ ﺍﺳﺖ ﻭ ﺩﺭ ﺧﻂ ﺩﻭﻡ ‪n‬‬
‫ﻋﺪﺩ ﺍﻭﻟﻴﻪ ﺑﻪ ﺗﺮﺗﻴﺐ ﺳﺎﻋﺘﮕﺮﺩ‪ ،‬ﺑﺎ ﺷﺮﻭﻉ ﺍﺯ ﻣﮑﺎﻥ ﺍﻭﻟﻴﻪﯼ ﺩﺳﺘﻪ ﺁﻣﺪﻩﺍﻧﺪ‪.‬‬
‫ﺑﺎ ﺷﺮﻭﻉ ﺍﺯ ﺧﻂ ﺳﻮﻡ‪ ،‬ﺩﺳﺘﻮﺭﺍﺕ ﻫﺮﮐﺪﺍﻡ ﺩﺭ ﻳﮏ ﺧﻂ ﻭ ﺑﺼﻮﺭﺕ ﻳﮑﯽ ﺍﺯ ﺳﻪ ﻧﻮﻉ ﺯﻳﺮ ﺁﻣﺪﻩﺍﻧﺪ‪:‬‬
‫‪ Del a ‬‬
‫‪delete command with an integer argument ‬‬
‫‪ ‬‬
‫‪ Ins a b ‬‬
‫‪insert command with two integer argument ‬‬
‫‪ ‬‬
‫‪ Print ‬‬
‫‪print command ‬‬
‫ﺩﺭ ﺍﻧﺘﻬﺎ ﺩﺭ ﻳﮏ ﺧﻂ ﮐﻠﻤﻪﯼ ‪ END‬ﺑﻪ ﻣﻌﻨﺎﯼ ﭘﺎﻳﺎﻥ ﺩﺳﺘﻮﺭﺍﺕ ﺁﻣﺪﻩﺍﺳﺖ‪.‬‬
‫ﻭﺭﻭﺩﯼ ﻭ ﺧﺮﻭﺟﯽ ﻧﻤﻮﻧﻪ‬
‫ﺧﺮﻭﺟﯽ‬
‫ﻭﺭﻭﺩﯼ‬
‫‪3 ‬‬
‫‪4 ‬‬
‫‪5 ‬‬
‫‪1 ‐2 3 0 4 ‬‬
‫‪Ins 2 0 ‬‬
‫‪Del ‐2 ‬‬
‫‪Print ‬‬
‫‪Del 2 ‬‬
‫‪Print ‬‬
‫‪END‬‬
‫ﻣﺤﺪﻭﺩﻳﺖﻫﺎ ‪ ‬‬
‫‪ ‬ﻭﺍﺿﺢ ﺍﺳﺖ ﮐﻪ ﺍﺳﺘﻔﺎﺩﻩ ﺍﺯ ﮐﻼﺱﻫﺎﯼ ﺁﻣﺎﺩﻩ ﻣﺎﻧﻨﺪ ‪ LinkedList‬ﻣﺠﺎﺯ ﻧﻤﯽﺑﺎﺷﺪ‪.‬‬
‫‪ ‬ﻗﺪﺭﻣﻄﻠﻖ ﻋﺪﺩ ﻧﻮﺷﺘﻪ ﺷﺪﻩ ﺩﺭ ﻫﺮ ﺧﺎﻧﻪ ﺑﻴﺶ ﺍﺯ ‪ 100 ‬ﻧﺨﻮﺍﻫﺪ ﺑﻮﺩ‪ .‬‬
‫‪ ‬ﭘﺲ ﺍﺯ ﺍﻧﺠﺎﻡ ﻫﺮ ﺩﺳﺘﻮﺭ‪ ،‬ﺗﻌﺪﺍﺩ ﺍﻋﺪﺍﺩ ﻫﻤﻮﺍﺭﻩ ﮐﻤﺘﺮ ﺍﺯ ‪ 5000‬ﺧﻮﺍﻫﺪ ﺑﻮﺩ‪.‬‬
‫ﺳﻮﺍﻝ ﺩﻭﻡ‪ :‬ﺑﺎﺯﺷﻨﺎﺳﯽ ﺭﺷﺘﻪ ﻫﺎﯼ ﻣﮑﻤﻞ‪-‬ﻣﺘﻘﺎﺭﻥ‬
‫ﻣﻘﺪﻣﻪ‬
‫ﻫﺮ ﺭﺷﺘﻪ ﯼ ‪ DNA‬ﺭﺍ ﻣﯽ ﺗﻮﺍﻥ ﺑﺎ ﻳﮏ ﺭﺷﺘﻪ ﺍﺯ ﮐﺎﺭﺍﮐﺘﺮ ﻫﺎﯼ }‪ {A,C,G,T‬ﻧﺸﺎﻥ ﺩﺍﺩ‪ .‬ﻫﺮ ﻳﮏ ﺍﺯ ﺍﻳﻦ ﮐﺎﺭﺍﮐﺘﺮ ﻫﺎ‬
‫ﻧﺸﺎﻥ ﺩﻫﻨﺪﻩ ﯼ ﻳﮑﯽ ﺍﺯ ﭘﺮﻭﺗﺌﻴﻦ ﻫﺎﯼ ﺳﺎﺧﺘﺎﺭﯼ ﺭﺷﺘﻪ ﯼ ‪ DNA‬ﺍﺳﺖ‪ ،‬ﭘﺮﻭﺗﺌﻴﻦ ‪ A‬ﻣﮑﻤﻞ ﭘﺮﻭﺗﺌﻴﻦ ‪ T‬ﻭ ﭘﺮﻭﺗﺌﻴﻦ ‪C‬‬
‫ﻞ ﺩﻭ ﺭﺷﺘﻪ ﯼ ‪ ،DNA‬ﺳﺎﺧﺘﺎﺭ ﻧﺮﺩﺑﺎﻧﯽ ﻣﻮﻟﮑﻮﻟﻬﺎﯼ‬
‫ﻣﮑﻤﻞ ﭘﺮﻭﺗﺌﻴﻦ ‪ G‬ﺍﺳﺖ‪ .‬ﺑﺎ ﺟﻔﺖ ﺷﺪﻥ ﭘﺮﻭﺗﺌﻴﻦ ﻫﺎﯼ ﻣﮑﻤ ِ‬
‫‪ DNA‬ﺷﮑﻞ ﻣﯽ ﮔﻴﺮﺩ‪ .‬‬
‫ﺭﺷﺘﻪ ﯼ ﻣﮑﻤﻞ‪ -‬ﻣﺘﻘﺎﺭﻥ ‪ ‬‬
‫ﻳﮏ ﺭﺷﺘﻪ ﺩﺭ ﺻﻮﺭﺗﯽ ﻣﮑﻤﻞ‪-‬ﻣﺘﻘﺎﺭﻥ ﺍﺳﺖ ﮐﻪ ﺍﮔﺮ ﺗﺒﺪﻳﻼﺕ ‪ A↔T‬ﻭ ‪ C↔G‬ﺭﺍ ﺩﺭ ﺁﻥ ﺍﻧﺠﺎﻡ ﺩﻫﻴﻢ‪ ،‬ﺭﺷﺘﻪ ﯼ‬
‫ﺣﺎﺻﻞ ﻋﮑﺲ ﺭﺷﺘﻪ ﯼ ﺍﻭﻟﻴﻪ ﺑﺎﺷﺪ‪ .‬ﺑﻪ ﻋﻨﻮﺍﻥ ﻣﺜﺎﻝ ﺍﮔﺮ ﺗﺒﺪﻳﻼﺕ ﺑﺎﻻ ﺭﺍ ﺭﻭﯼ ﺭﺷﺘﻪ ﯼ ‪ AACGTT‬ﺍﻧﺠﺎﻡ ﺩﻫﻴﻢ‪ ،‬ﺭﺷﺘﻪ‬
‫ﯼ ﺣﺎﺻﻞ ‪ TTGCAA‬ﺧﻮﺍﻫﺪ ﺑﻮﺩ‪ .‬ﺍﺯ ﺁﻥ ﺟﺎ ﮐﻪ ﺭﺷﺘﻪ ﯼ ﺑﻪ ﺩﺳﺖ ﺁﻣﺪﻩ ﻋﮑﺲ ﺭﺷﺘﻪ ﯼ ﺍﻭﻟﻴﻪ ﺍﺳﺖ‪ ،‬ﺭﺷﺘﻪ ﯼ‬
‫‪ AACGTT ‬ﻣﮑﻤﻞ‪-‬ﻣﺘﻘﺎﺭﻥ ﻣﯽ ﺑﺎﺷﺪ‪.‬‬
‫‪ ‬‬
‫ﺷﮑﻞ ‪ -١‬ﻣﺜﺎﻟﯽ ﺍﺯ ﻳﮏ ﺭﺷﺘﻪ ﯼ ﻣﮑﻤﻞ‪ -‬ﻣﺘﻘﺎﺭﻥ‬
‫ﺭﺷﺘﻪ ﻫﺎﯼ ‪ DNA‬ﻣﮑﻤﻞ‪-‬ﻣﺘﻘﺎﺭﻥ ﻭﻳﮋﮔﯽ ﻫﺎﯼ ﺯﻳﺴﺖ ﺷﻨﺎﺧﺘﯽ ﻣﻬﻤﯽ ﺩﺍﺭﻧﺪ‪ ،‬ﺑﺮﺍﯼ ﻣﺜﺎﻝ ﺍﻳﻦ ﺭﺷﺘﻪ ﻫﺎ ﺑﺎ ﺗﺎ ﺷﺪﻥ‬
‫ﺭﻭﯼ ﺧﻮﺩﺷﺎﻥ ﻣﯽ ﺗﻮﺍﻧﻨﺪ ﻳﮏ ﻣﻮﻟﮑﻮﻝ ‪ DNA‬ﺗﺸﮑﻴﻞ ﺩﻫﻨﺪ‪ ،‬ﺑﻪ ﺍﻳﻦ ﺗﺮﺗﻴﺐ ﻣﯽ ﺗﻮﺍﻥ ﺑﺮﺧﯽ ﮊﻥ ﻫﺎ ﺭﺍ ﺗﺮﻣﻴﻢ ﮐﺮﺩ‪.‬‬
‫ﺻﻮﺭﺕ ﻣﺴﺌﻠﻪ‬
‫ﺑﺮﻧﺎﻣﻪ ﺍﯼ ﺑﻨﻮﻳﺴﻴﺪ ﮐﻪ ﻳﮏ ﺭﺷﺘﻪ ﺍﺯ ﮐﺎﺭﺍﮐﺘﺮﻫﺎﯼ }‪ {A,C,G,T‬ﺍﺯ ﻭﺭﻭﺩﯼ ﺑﺨﻮﺍﻧﺪ ﻭ ﺗﻌﻴﻴﻦ ﮐﻨﺪ ﮐﻪ ﺁﻳﺎ ﺍﻳﻦ ﺭﺷﺘﻪ‬
‫ﻣﮑﻤﻞ‪ -‬ﻣﺘﻘﺎﺭﻥ ﻫﺴﺖ ﻳﺎ ﺧﻴﺮ‪.‬‬
‫ﺩﺭ ﻧﻮﺷﺘﻦ ﺍﻳﻦ ﺑﺮﻧﺎﻣﻪ ﺑﻪ ﻧﮑﺎﺕ ﺯﻳﺮ ﺗﻮﺟﻪ ﮐﻨﻴﺪ‪:‬‬
‫‪ ‬ﺩﺭ ﺍﻳﻦ ﺑﺮﻧﺎﻣﻪ ﺗﻨﻬﺎ ﻣﺠﺎﺯﻳﺪ ﺍﺯ ﺩﻭ ﭘﺸﺘﻪ‪ ٥‬ﺑﺮﺍﯼ ﺗﺸﺨﻴﺺ ﻣﮑﻤﻞ‪ -‬ﻣﺘﻘﺎﺭﻥ ﺑﻮﺩﻥ ﺍﺳﺘﻔﺎﺩﻩ ﮐﻨﻴﺪ ﻭ ﻧﺒﺎﻳﺪ‬
‫ﺳﺎﺧﺘﻤﺎﻥ ﺩﺍﺩﻩ ﻫﺎﯼ ﺩﻳﮕﺮ ﻧﻈﻴﺮ ﺁﺭﺍﻳﻪ‪ ،‬ﻟﻴﺴﺖ‪ ،‬ﺻﻒ ﻭ ‪ ...‬ﺭﺍ ﻣﻮﺭﺩ ﺍﺳﺘﻔﺎﺩﻩ ﻗﺮﺍﺭ ﺩﻫﻴﺪ‪ .‬ﺑﻪ ﻋﺒﺎﺭﺕ ﺩﻳﮕﺮ‪ ،‬ﻗﺒﻞ‬
‫ﺍﺯ ﻗﺮﺍﺭ ﺩﺍﺩﻥ ﺗﻤﺎﻡ ﺩﺍﺩﻩ ﻫﺎ ﺩﺭ ﺍﻳﻦ ﺩﻭ ﭘﺸﺘﻪ ﺍﺟﺎﺯﻩ ﯼ ﺍﻧﺠﺎﻡ ﻫﻴﭻ ﭘﺮﺩﺍﺯﺷﯽ ﺭﺍ ﺭﻭﯼ ﻭﺭﻭﺩﯼ ﻧﺪﺍﺭﻳﺪ‪ .‬ﺑﻪ ﺑﺮﻧﺎﻣﻪ‬
‫ﻫﺎﻳﯽ ﮐﻪ ﺍﺯ ﺩﺍﺩﻩ ﺳﺎﺧﺘﺎﺭﻫﺎﯼ ﺩﻳﮕﺮ ﺍﺳﺘﻔﺎﺩﻩ ﮐﺮﺩﻩ ﺑﺎﺷﻨﺪ ﻧﻤﺮﻩ ﺍﯼ ﺗﻌﻠﻖ ﻧﺨﻮﺍﻫﺪ ﮔﺮﻓﺖ‪ .‬‬
‫)ﺭﺍﻫﻨﻤﺎﻳﯽ‪ :‬ﻭﻗﺘﯽ ﺩﻭ ﭘﺸﺘﻪ ﺩﺍﺷﺘﻪ ﺑﺎﺷﻴﻢ ﻭ ﺑﺨﻮﺍﻫﻴﻢ ﺑﻪ ﻋﻨﺼﺮ ﺯﻳﺮﻳﻦ ﻳﮑﯽ ﺍﺯ ﺁﻥ ﻫﺎ ﺩﺳﺘﺮﺳﯽ ﺩﺍﺷﺘﻪ‬
‫ﺑﺎﺷﻴﻢ‪ ،‬ﻣﯽ ﺗﻮﺍﻧﻴﻢ ﻳﮑﯽ ﻳﮑﯽ ﻋﻨﺎﺻﺮ ﺭﺍ ﺍﺯ ﻳﮑﯽ ﺍﺯ ﺁﻥ ﻫﺎ ‪ pop‬ﻭ ﺩﺭ ﺩﻳﮕﺮﯼ ‪ push‬ﮐﻨﻴﻢ‪ ،‬ﺑﻪ ﺍﻳﻦ ﺗﺮﺗﻴﺐ‬
‫ﻣﯽ ﺗﻮﺍﻧﻴﻢ ﺑﻪ ﻋﻨﺼﺮ ﺯﻳﺮﻳﻦ ﻫﺮ ﭘﺸﺘﻪ ﺩﺳﺘﺮﺳﯽ ﭘﻴﺪﺍ ﮐﻨﻴﻢ‪(.‬‬
‫‪ ‬ﺳﺎﺧﺘﻤﺎﻥ ﺩﺍﺩﻩ ﯼ ‪ stack‬ﺭﺍ ﺑﺎﻳﺪ ﺧﻮﺩﺗﺎﻥ )ﺑﻪ ﻳﮑﯽ ﺍﺯ ﺭﻭﺵ ﻫﺎﯼ ﮔﻔﺘﻪ ﺷﺪﻩ ﺩﺭ ﮐﻼﺱ( ﭘﻴﺎﺩﻩ ﺳﺎﺯﯼ‬
‫ﮐﻨﻴﺪ‪ .‬ﺍﻳﻦ ﺳﺎﺧﺘﻤﺎﻥ ﺩﺍﺩﻩ ﺑﺎﻳﺪ ﺩﺭ ﻳﮏ ﻓﺎﻳﻞ ‪ stack.java‬ﻳﺎ ‪ stack.cpp‬ﺑﺎﺷﺪ ﻭ ﻣﺘﺪﻫﺎﯼ ‪ push‬ﻭ‬
‫‪ pop‬ﺩﺭ ﺁﻥ ﭘﻴﺎﺩﻩ ﺳﺎﺯﯼ ﺷﺪﻩ ﺑﺎﺷﻨﺪ‪ .‬‬
‫‪ ‬ﺗﺎﺑﻊ )(‪ main‬ﺑﺮﻧﺎﻣﻪ ﯼ ﺷﻤﺎ ﺑﺎﻳﺪ ﺩﺭ ﻳﮏ ﻓﺎﻳﻞ ‪ Main.java‬ﻳﺎ ‪ Main.cpp‬ﺑﺎﺷﺪ ‪ .‬‬
‫ﻭﺭﻭﺩﯼ ﻭ ﺧﺮﻭﺟﯽ ﺑﺮﻧﺎﻣﻪ‪:‬‬
‫ﺑﺮﻧﺎﻣﻪ ﯼ ﺷﻤﺎ ﺑﺎﻳﺪ ﺧﻂ ﺑﻪ ﺧﻂ ﺭﺷﺘﻪ ﻫﺎﯼ ﻭﺭﻭﺩﯼ ﺭﺍ ﺍﺯ ‪ console‬ﺑﺨﻮﺍﻧﺪ )ﺩﺭ ﻫﺮ ﺧﻂ ﻳﮏ ﺭﺷﺘﻪ‪ ‬ﺩﺍﺩﻩ ﺷﺪﻩ ﻭ ﺩﺭ‬
‫ﻫﺮ ﺭﺷﺘﻪ ﺗﻨﻬﺎ ﺍﺯ ﮐﺎﺭﺍﮐﺘﺮﻫﺎﯼ ‪ T،G،C،A‬ﺍﺳﺘﻔﺎﺩﻩ ﺷﺪﻩ ﺍﺳﺖ‪ (.‬ﻭ ﺑﻪ ﺍﺯﺍﯼ ﻫﺮ ﺭﺷﺘﻪ ﺩﺭ ﺻﻮﺭﺗﯽ ﮐﻪ ﻣﮑﻤﻞ‪ -‬ﻣﺘﻘﺎﺭﻥ ﺑﻮﺩ‬
‫ﻋﺒﺎﺭﺕ ‪ True‬ﻭ ﺩﺭ ﻏﻴﺮ ﺍﻳﻦ ﺻﻮﺭﺕ ﻋﺒﺎﺭﺕ ‪ False‬ﺭﺍ ﭼﺎﭖ ﮐﻨﺪ‪ .‬ﺑﺮﻧﺎﻣﻪ ﺯﻣﺎﻧﯽ ﺗﻤﺎﻡ ﻣﯽ ﺷﻮﺩ ﮐﻪ ﺍﺯ ﻭﺭﻭﺩﯼ ﮐﺎﺭﺍﮐﺘﺮ‬
‫ﺻﻔﺮ ﺭﺍ ﺑﺨﻮﺍﻧﺪ‪ .‬‬
‫ﻧﻤﻮﻧﻪ ﯼ ﻭﺭﻭﺩﯼ ﻭ ﺧﺮﻭﺟﯽ‪:‬‬
‫‪ ‬‬
‫‪ stack ‬‬
‫‪5‬‬
‫ﻭﺭﻭﺩﯼ‬
‫ﺧﺮﻭﺟﯽ‬
AGCTAGCT
AACTT
AACGTT
A
AGGA
AT 0
True
False
True
False
False
True
End