C programming
COMP281 Resit Assignment 2 – C Programming
! The following 5 problems will be available as Resit Assignment 2 on the online judging system
available at http://intranet.csc.liv.ac.uk/JudgeOnline/ ! You need to write a valid C program that solves each of these problems – it must read the input, as
specified in the problem description then print the solution to the given problem for that input. ! Input is read from the standard input, in the same way that you read input from the keyboard as shown in
lectures (e.g., using scanf). Output is also printed to the standard output, as you have seen (e.g., using printf).
! When you are satisfied that your programs work correctly, you must submit them through the departmental submission system, as described below.
! You must also include a brief report describing your solutions to the problems. This should be up to one side of A4 paper (although there is no penalty for a longer report) and should give a description of how each of your solutions works. This should include describing the algorithm used to reach the solution, describing your use of any C language features (that were not discussed in lectures), identifying any resources that you have used to help you solve the problems and describing any joint work you may have done with other students.
! This assignment is worth 30% of the total mark for COMP281
• 50% of the marks will be awarded for programs that correctly solve the problem for all test cases.
All problems are weighted equally and each counts for 20% of this total.
• 40% of the marks will be awarded depending on the style, comments and efficiency of the solution. All problems are weighted equally and each counts for 20% of this total.
• 10% of the marks will be awarded for the quality and depth of the accompanying report
• See separate marking guidelines for more details.
Submission Instructions
• Name each of your c files according to the problem number; i.e., 1071.c,1072.c,1073.c,1038.c and 1042.c. Place all five of your C files and your report (in .pdf format) into a single zip file.
• All question have also been/will also be posted on www.csc.liv.ac.uk/JudgeOnline2 • Before you submit your solutions, please first test them using the online judge. You are
required to include the “Result” and the “RunID” in your C code as comments. The OJ provides a RunID. RunIDs are not problem IDs.
o Example: the problem is 10xx . The solution has been accepted by the OJ, and the runID is 2033. You add to your code: /* 2033 Accepted */
o Result is one of the following: Accepted, Wrong Answer, Presentation Error, Time Limit Exceeded, Memory Limit Exceeded, Output Limit Exceeded, Runtime Error, Compile Error
• Submit this zip file using the departmental submission system at : http://www.csc.liv.ac.uk/cgi-bin/submit.pl
The deadline for this assignment is August 17th, 4:00pm • Penalties for late submission apply in accordance with departmental policy as set out in the
student handbook, which can be found at: http://www.csc.liv.ac.uk/student/ugpdfhandbook.pdf
Problem 1071 Title: Atbash Cipher Description Atbash Cipher is a simple substitution cipher. Applying Atbash Cipher to a piece of text requires replacing each alphabetic character by the corresponding letter from the reverse of the alphabet. A becomes Z, B becomes Y, and so on up to M becomes N. Then N becomes M, O becomes L and so on up to Z becomes A. Only those 26 letters which occur in the English alphabet are affected; numbers, symbols, whitespace, and all other characters are left unchanged. Input One line of characters (ends with EOF) Output The result after applying Atbash to the input Sample Input ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1! Sample Output ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba1! Problem 1072 Title: Sort strings in reverse alphabetical order Description Given several input strings, print out the one that is first in reverse alphabetical order. Input Each line of input contains a string (containing English uppercase characters only). Each string may be between 5 and 5,000 characters long (inclusive). The input ends with a blank line. Output The string that is first in reverse alphabetical order. Sample Input STRING STRINGCOULDBEVERYLONG ASTRING STRINGFOUR TRIING GNIRTS
BSTRING STRINGING end Sample Output TRIING Problem 1073 Title: Difference of two matrices Description Input two positive integers n and m. Then input two matrices (n rows by m columns). Output the matrix difference (should also be n rows by m columns). Hint: Consider using malloc and "pointers to pointers". Input n, m, and two matrices Output Difference of these two matrices Sample Input 3 2 2 1 0 5 7 -1 1 1 0 0 3 3 Sample Output 1 0 0 5 4 -4 Problem 1042 Title: Anagram? Description An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once. For example, "orchestra" can be rearranged into "carthorse", and "Debit card" can be rearranged into "Bad credit". Note: case is ignored.
Input Two phrases, one per line. Each phrase consists of only English letters (a-z and A-Z) and spaces.
Output Whether the two phrases are anagrams of each other ("Yes" or "No"). Sample Input Payment received Every cent paid me Sample Output Yes Problem 1038 Title: Concatenation of strings Description Input two strings (length<=100), one for each line. Output the joined string. You are not allowed to use functions defined in string.h. The joined string should be placed in space allocated using malloc. Input string1 string2 Output Joined string Sample Input Where do you come from? I come from Leuven in Belgium. Sample Output Where do you come from?I come from Leuven in Belgium.