Διάπκεια 3 ώπερ. Να απανηηθούν όλερ οι επωηήζειρ Ππόβλημα 1: ABC (Μονάδερ: 15) Θα ζνπ δίλνληαη από ην πιεθηξνιόγην ηξεηο ζεηηθνί αθέξαηνη Α, Β θαη C. Οη αξηζκνί δελ είλαη απαξαίηεην λα δνζνύλ κε απηή ηε ζεηξά, αιιά ζίγνπξα ν Α ζα είλαη κηθξόηεξνο από ηνλ B θαη ν B κηθξόηεξνο από ηνλ C. Γηα λα ην θάλνπκε πην επράξηζην νπηηθά, λα γξάςεηε έλα πξόγξακκα πνπ λα ηνπο δηαβάδεη θαη λα ηνπο εκθαλίδεη ζηελ νζόλε κε ηε ζεηξά πνπ ζαο δίλνληαη. Η πξώηε γξακκή πεξηέρεη ηξεηο ζεηηθνύο αθέξαηνπο αξηζκνύο Α, B θαη C, όρη απαξαίηεηα ζε απηή ηε ζεηξά. Καη νη ηξεηο αξηζκνί είλαη κηθξόηεξνη ή ίζνη ηνπ 100. Η δεύηεξε γξακκή πεξηέρεη ηξία θεθαιαία γξάκκαηα Α, Β θαη C (ρσξίο θελά δηαζηήκαηα κεηαμύ ηνπο) αληηπξνζσπεύνληαο ηελ επηζπκεηή ζεηξά κε ηελ νπνία ζα πξέπεη λα εκθαλίδνληαη. Μηα κόλν γξακκή κε ηελ επηζπκεηή ζεηξά ησλ αθεξαίσλ A, B θαη C, νη νπνίνη δηαρσξίδνληαη κε έλα θελό δηάζηεκα. Παπαδείγμαηα 1 5 3 ABC 1 3 5 6 4 2 CAB 6 2 4 1 P a g e http://www.pspo.org.cy/
Duration 3 hours Answer all questions Problem 1: ABC (Points: 15) You will be given from the keyboard three positive integers A, B and C. The numbers will not be given in that exact order, but we do know that A is less than B and B less than C. In order to have a more pleasant viewing, write a program to rearrange them and display them on the screen in the given order. The first line contains three positive integers A, B and C, not necessarily in that order. All three numbers will be less than or equal to 100. The second line contains three uppercase letters 'A', 'B' and 'C' (with no spaces between them) representing the desired order. integers A, B and C in the desired order on a single line, separated by a single space. Sample test data 1 5 3 ABC 1 3 5 6 4 2 CAB 6 2 4 2 P a g e http://www.pspo.org.cy/
Ππόβλημα 2: Επαναλήψειρ (Μονάδερ: 15) Να γξαθεί πξόγξακκα ην νπνίν θηίδεη κηα ζθάια από ραξαθηήξεο. Τν πξόγξακκα απηό δέρεηαη σο είζνδν κηα ζπκβνινζεηξά από ην πιεθηξνιόγην, πνπ δελ μεπεξλά ηνπο 78 ραξαθηήξεο. Γηα θάζε ραξαθηήξα εηζόδνπ, ην πξόγξακκα εκθαλίδεη ζε λέα γξακκή ηνλ ραξαθηήξα i θνξέο ζηελ νζόλε (όπνπ i ε ζέζε ηνπ ραξαθηήξα ζηε ζπκβνινζεηξά εηζόδνπ). Η ζπκβνινζεηξά εηζόδνπ πεξηέρεη κόλν ραξαθηήξεο από ην ιαηηληθό αιθάβεην (δειαδή, a-z θαη A-Z) Μηα ζπκβνινζεηξά πνπ λα ηεξεί ηηο πξνδηαγξαθέο ηνπ πξνβιήκαηνο. Παπαδείγμαηα asdf a ss ddd ffff asdad a ss ddd aaaa ddddd 3 P a g e http://www.pspo.org.cy/
Problem 2: Loops (Points: 15) Write a program that builds a staircase of characters. This program accepts as input a string of characters from the keyboard (max length 78 characters). For each input character the program displays a new line on the screen that contains the character i times (where i is the position of the character in the input string). The input string consists only of characters of the Latin alphabet (i.e. a-z and A-Z). A string of characters that complies with the requirements of the problem. Sample test data asdf a ss ddd ffff asdad a ss ddd aaaa ddddd 4 P a g e http://www.pspo.org.cy/
Ππόβλημα 3: Πποκαηαπκηική εκηέλεζη (Μονάδερ: 15) Με ηελ κέζνδν ηεο πξνθαηαξθηηθήο εθηέιεζεο (dry run), θαηαγξάςεηε βήκα-πξνοβήκα ηηο ηηκέο ησλ κεηαβιεηώλ i θαη j κέρξη ηέινπο. Φξεζηκνπνηείζηε ηηο αξρηθέο ηηκέο i =2 θαη j = 6. Function Looping(i, j) if ( i < j ) return ( i * Looping(i+1,j) ); else return i; Ππόβλημα 4: Ανηιζηποθή (Μονάδερ: 25) Να γξάςεηε έλα πξόγξακκα ην νπνίν δηαβάδεη από ην πιεθηξνιόγην κηα γξακκή κήθνπο ην πνιύ 60 ραξαθηήξσλ θαη ηελ ηππώλεη αληεζηξακκέλε. Υπόδεημε: Γηα λα ην πεηύρεη απηό ην πξόγξακκα ζαο ππέπει λα ρξεζηκνπνηήζεη κηα recursive δηαδηθαζία ηελ νπνία ζα νλνκάζεηε PushTheCharacters. Μηα γξακκή πνπ απνηειείηαη από Ν ραξαθηήξεο (όπνπ, 1 Ν 60) Μηα γξακκή πνπ πεξηέρεη ηελ γξακκή εηζόδνπ αληεζηξακκέλε. Παπάδειγμα Ειζόδορ qwerty Εξόδορ ytrewq 5 P a g e http://www.pspo.org.cy/
Problem 3: Dry Run (Μονάδερ: 15) Using the dry run method, write step-by-step the values of the variables i and j until termination. Use initial values i =2 and j = 6. Function Looping(i, j) if ( i < j ) return ( i * Looping(i+1,j) ); else return i; Problem 4: Reverse (Points: 25) Write a program that reads from the keyboard, one line with maximum length 60 characters and prints it in reverse order. Note: You must use a recursive function to achieve this which will be named PushTheCharacters. A line that is composed from N characters (where, 1 N 60) A line that contains the input line reversed. Sample test data qwerty ytrewq 6 P a g e http://www.pspo.org.cy/
Ππόβλημα 5: Κπςθέρ Λέξειρ (Μονάδερ: 30) Να γξάςεηε πξόγξακκα ην νπνίν δηαβάδεη από ην αξρείν edgar.txt κία γξακκή θάζε θνξά. Κάζε γξακκή πεξηέρεη αξηζκό ιέμεσλ νη νπνίεο ρσξίδνληαη κεηαμύ ηνπο κε έλα θελό ραξαθηήξα ή ηειεία. Τν πξόγξακκα ζαο πξέπεη λα ειέγρεη ηε γξακκή θαη λα ηελ εκθαλίδεη ζηελ νζόλε αλ ζε απηή πεξηέρνληαη κία ή πεξηζζόηεξεο από ηηο πην θάησ ιέμεηο, είηε γξακκέλεο θαλνληθά είηε κε ηα γξάκκαηα ηνπο ζε ηπραία δηάηαμε. Λέμεηο πνπ αλαδεηνύληαη: sit, won, to, not Η θάζε γξακκή απνηειείηαη από 80 ην πνιύ ραξαθηήξεο, θαη ιέμεηο απνηεινύληαη ην πνιύ από 15 ραξαθηήξεο. Μ γξακκέο πνπ απνηειείηαη από Ν ραξαθηήξεο (όπνπ, 1 Ν 80, 1 Μ) Κ γξακκέο, νη νπνίεο είλαη νη γξακκέο όπνπ βξέζεθαλ ζε απηέο νη θξπθέο ιέμεηο (K M) Παπάδειγμα Ειζόδορ page now lying before not be found with any integers signal. This has been already too much an object oriented The value cannot be found. There must be an error. The upper regions of the globe have not the. continue to search however its nothing there. Oh this is a sample of a text. To the earth and moon are forever not to its dreams. to its flowers, to its golden goals. perfect and limitless programs exist. it not hang eternally between their loops and programming Εξόδορ page now lying before not be found with any integers The upper regions of the globe have not the. continue to search however its nothing there. To the earth and moon are forever not to its dreams. to its flowers, to its golden goals. perfect and limitless programs exist. it not hang eternally 7 P a g e http://www.pspo.org.cy/
Problem 5: Hidden Words (Points: 30) Write a program that reads from file edgar.txt, one line at a time. Each line consists of a number of words separated by a blank character or a dot. Your program must check each line and display it on the screen if it contains one of the following words, either written correctly or written with their letters in a random order. Words to look for: sit, won, to, not Each line consists of at most 80 characters, and each word of at most 15 characters. M lines that are composed from N characters (where, 1 Ν 80, 1 Μ) K lines, which are the ones in which your program found hidden words. (K M) Sample test data page now lying before not be found with any integers signal. This has been already too much an object oriented The value cannot be found. There must be an error. The upper regions of the globe have not the. continue to search however its nothing there. Oh this is a sample of a text. To the earth and moon are forever not to its dreams. to its flowers, to its golden goals. perfect and limitless programs exist. it not hang eternally between their loops and programming page now lying before not be found with any integers The upper regions of the globe have not the. continue to search however its nothing there. To the earth and moon are forever not to its dreams. to its flowers, to its golden goals. perfect and limitless programs exist. it not hang eternally 8 P a g e http://www.pspo.org.cy/