به نام خدا دانشگاه صنعتی شريف دانشکده مهندسی کامپيوتر درس مبانی برنامهسازی پيک شادی (تمرين سری دوم) سال نو مبارک
توضيحات : قبل از شروع موارد زير را به دقت بخوانيد. در خط اول هر يک از برنامهها شماره دانشجويی خود را به فرمت زير بنويسيد: // ID: yur Student ID مثال: // ID: 8765432 بعد از نوشتن همه برنامهها همه ا نها را در يک فولدر با نام assignment#2_stdid قرار دهيد( که در ا ن stdid شماره دانشجويی شما می باشد.) مثلا : assignment#2_8765432 و سپس اين فولدر را فشرده کنيد. فايل فشرده شده را به ا درس cpphmewrk852@gmail.cm ارسال نماييد. stdid عنوان ايميل بايد به صورت assignment#2_stdid دانشجويی شما می باشد. باشد که در ا ن شماره اشتباه در نامگذاری فايل برنامهها و فايل فشرده شده و يا عنوان ايميل فرستاده شده موجب عدم تصحيح تمرين شما میشود. فرمت ورودی و خروجی برنامههای شما بايد دقيقا به صورت گفته شده در مسي له باشد در غير اين صورت چون برنامههای شما به صورت خودکار تصحيح می شود خروجی برنامهی شما با خروجی برنامهی مصحح منطبق نخواهد بود. به هر يک از برنامههای شما تعدادی تست داده خواهد شد. تستهای نمونه را به برنامههای تان بدهيد. توصيه می شود که حتما يک بار به برنامههای مشابه به ميزان نمره سوال نمره منفی تعلق خواهد گرفت. موفق باشيد. برای اين کار کافی است روی فولدر کليک راست کنيد و از منوی باز شده Send t و سپس (Zipped) Cmpressed Flder را انتخاب کنيد. با اين کار يک فايل به نام assignment#_stdid.zip ساخته می شود. 2
مسي له اول ------------------------------------------------------------ نام فايل برنامه : BigNumber.cpp در اين مسي له شما بايد دو عدد را از ورودی بخوانيد و بتوانيد سه عمليات زير را روی ا نها انجام دهيد : i. دو عدد را با هم جمع کنيد..ii دو عدد را در هم ضرب کنيد..iii عدد اول را به توان عدد دوم برسانيد. و نتيجه را در خروجی چاپ کنيد. به همين راحتی!!! توجه داشته باشيد که جواب ها ) و يا حتی ورودی ها ( می توانند تا 000 رقم داشته باشند.( يعنی خيلی بزرگ هستند.) راهنمايی : انواع عددی استاندارد در C حداکثر اعداد تا 60 رقم را پشتيبانی می کنند. بنابراين نمی توانيد از انواع عددی C استفاده کنيد و بايد فکر ديگری بکنيد. راهنمايی 2: برای جمع کردن می توانيد ورودی ها را به صورت ا رايه ای از کاراکترها بگيريد و وظيفه خطير جمع کردن را خود به عهده بگيريد! راهنمايی 3: اگر جمع را به صورت تابع بنويسيد پياده سازی ضرب و توان به ا سانی انجام پذير است. قالب ورودی و خروجی ها : ورودی را به صورت استاندارد ) از صفحه کليد ( بخوانيد. در خط اول n تعداد پرسش ها از برنامه شما می ا يد. در n خط بعدی در هر خط می تواند يکی از قالب های زير بيايد : ADD num num2 در اين حالت اعداد num و num2 را با هم جمع می کنيد. MUL num num2 در اين حالت اعداد num و num2 را در هم ضرب می کنيد. POW num num2 در اين حالت عدد num را به توان عدد num2 می رسانيد. در هر سه حالت جواب را در يک خط در خروجی استاندارد چاپ می کنيد. تذکر : دقت کنيد که همه حروف MUL ADD و POW بزرگ است. نمونه ورودی و خروجی ها را در زير مشاهده می کنيد : 4 ADD 9999999999 2 MUL 00 23456789 POW 2 00 ADD 20-00 خروجی نمونه : 000000000 2345678900 26765060022822940496703205376-80 ورودی نمونه : int64 و... مثل lngint int 3
و 8 و 5 و 8 مسي له دوم ------------------------------------------------------------ نام فايل برنامه : Interval.cpp در اين مسا له شما بايد پس از دريافت حدود 5 بازه از ورودی اجتماع ا نها را بيابيد و در خروجی چاپ کنيد. توجه کنيد که بايد حتیالامکان حدود کمتری را برای بازهها ذکر کنيد. مثلا مجموع دو بازهی ) ) و ) 3) را به صورت ) ) در نظر بگيريد. قالب ورودی و خروجی ها : ورودی را در 5 خط و در هر خط 2 عدد بخوانيد. هر خط نشانهی يک بازه است. عدد اول هر خط نشانهی حد سمت چپ و عدد دوم نشانهی حد سمت راست بازهاند. خروجی میتواند شامل چندين بازه شود. لذا در خط اول ا ن تعداد بازهها (n) را بنويسيد و سپس در هر يک از n سطر بعد حدود يکی از بازهها را بنويسيد. توجه داشته باشيد که بايد بازهها را به ترتيب صعودی بنويسيد. - 4 4 9-6 2 2 2-30 -20 خروجی نمونه : ورودی نمونه : 3-30 -20-6 9 2 2 مسي له سوم ------------------------------------------------------------ نام فايل برنامه Check.cpp: Yur task is t write a prgram that reads a chessbard cnfiguratin and identifies whether a king is under attack (in check). A king is in check if it is n square which can be taken by the ppnent n his next mve. White pieces will be represented by uppercase letters, and black pieces by lwercase letters. The white side will always be n the bttm f the bard, with the black side always n the tp. Fr thse unfamiliar with chess, here are the mvements f each piece: Pawn (p r P): can nly mve straight ahead, ne square at a time. Hwever, it takes pieces diagnally, and that is what cncerns yu in this prblem. Knight (n r N): has an L-shaped mvement shwn belw. It is the nly piece that can jump ver ther pieces. Bishp (b r B): can mve any number f squares diagnally, either frward r backward. Rk (r r R): can mve any number f squares vertically r hrizntally, either frward r backward. Queen (q r Q): can mve any number f squares in any directin (diagnally, hrizntally, r vertically) either frward r backward. King (k r K): can mve ne square at a time in any directin (diagnally, hrizntally, r vertically) either frward r backward. Mvement examples are shwn belw, where * indicates the psitins where the piece can capture anther piece: 4
Pawn Rk Bishp Queen King Knight......*......*...*...*............*... *...*. *..*..*.............*....*...*...*.*.*.......*.*.........*.....*.*.....***.....***....*...*.....p... ***r****...b... ***q****..*k*......n.....*.*......*.....*.*.....***.....***....*...*........*....*...*...*.*.*.......*.*.........*... *...*. *..*..*....... Remember that the knight is the nly piece that can jump ver ther pieces. The pawn mvement will depend n its side. If it is a black pawn, it can nly mve ne square diagnally dwn the bard. If it is a white pawn, it can nly mve ne square diagnally up the bard. The example abve is a black pawn, described by a lwercase p. We use mve t indicate the squares where the pawn can capture anther piece. Input There is a bard cnfiguratin in the input, cnsisting f eight lines f eight characters. A. dentes an empty square, while upper and lwercase letters represent the pieces as defined abve. There will be n invalid characters and n cnfiguratins where bth kings are in check. The bard will cntain exactly ne white king and ne black king. Output Yu must utput ne f the fllwing answers: white king is in check. black king is in check. n king is in check. Sample input..k... ppp.pppp....r...b........ PPPPPPPP K... Sample Output black king is in check. rnbqk.nr ppp..ppp...p......p....bpp......n.. PP..PPPP RNBQKB.R white king is in check. 5
مسي له چهارم -------------------------------------------------------- ---- نام فايل برنامه Jlly.cpp: A sequence f n > 0 integers is called a jlly jumper if the abslute values f the differences between successive elements take n all pssible values thrugh n. Fr instance, 4 2 3 is a jlly jumper, because the abslute differences are 3, 2, and, respectively. The definitin implies that any sequence f a single integer is a jlly jumper. Write a prgram t determine whether each f a number f sequences is a jlly jumper. Input Each line f input cntains an integer n < 3, 000 fllwed by n integers representing the sequence. Output Fr each line f input generate a line f utput saying Jlly r Nt jlly. Sample input 4 4 2 3 5 4 2-6 Sample Output Jlly Nt jlly مسي له پنجم ------------------------------------------------------------ نام فايل برنامه Pker.cpp: A pker deck cntains 52 cards. Each card has a suit f either clubs, diamnds, hearts, r spades (dented C, D, H, and S in the input data). Each card als has a value f either 2 thrugh 0, jack, queen, king, r ace (dented 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A). Fr scring purpses card values are rdered as abve, with 2 having the lwest and ace the highest value. The suit has n impact n value. A pker hand cnsists f five cards dealt frm the deck. Pker hands are ranked by the fllwing partial rder frm lwest t highest. High Card. Hands which d nt fit any higher categry are ranked by the value f their highest card. If the highest cards have the same value, the hands are ranked by the next highest, and s n. Pair. Tw f the five cards in the hand have the same value. Hands which bth cntain a pair are ranked by the value f the cards frming the pair. If these values are the same, the hands are ranked by the values f the cards nt frming the pair, in decreasing rder. Tw Pairs. The hand cntains tw different pairs. Hands which bth cntain tw pairs are ranked by the value f their highest pair. Hands with the same highest pair are ranked by the value f their ther pair. If these values are the same the hands are ranked by the value f the remaining card. Three f a Kind. Three f the cards in the hand have the same value. Hands which bth cntain three f a kind are ranked by the value f the three cards. Straight. Hand cntains five cards with cnsecutive values. Hands which bth cntain a straight are ranked by their highest card. 6
Flush. Hand cntains five cards f the same suit. Hands which are bth flushes are ranked using the rules fr High Card. Full Huse. Three cards f the same value, with the remaining tw cards frming a pair. Ranked by the value f the three cards. Fur f a Kind. Fur cards with the same value. Ranked by the value f the fur cards. Straight Flush. Five cards f the same suit with cnsecutive values. Ranked by the highest card in the hand. Yur jb is t cmpare several pairs f pker hands and t indicate which, if either, has a higher rank. Input The input file cntains several lines (up t 0 lines), each cntaining the designatin f ten cards: the first five cards are the hand fr the player named Black and the next five cards are the hand fr the player named White. Output Fr each line f input, print a line cntaining ne f the fllwing: Black wins. White wins. Tie. Sample input Sample Output 2H 3D 5S 9C KD 2C 3H 4S 8C AH 2H 4S 4C 2D 4H 2S 8S AS QS 3S 2H 3D 5S 9C KD 2C 3H 4S 8C KH 2H 3D 5S 9C KD 2D 3H 5C 9S KH White wins. Black wins. Black wins. Tie. تمرينهاي خود را حداآثر تا ساعت 2 نيم شب 385//4 ارسال نماييد. تاريخ تحويل تمرين به هيچ وجه تمديد نميشود. 7