Sale!

COMP281 Assignment 2 C Programming solution

$30.00 $25.50

Category:

Description

5/5 - (5 votes)

Problem 1029
Title: ROT R 3
Description
ROT R 3 (“Rotate Right by 3”) is a simple substitution cipher to encode letters. Applying ROT R 3 to a
piece of text merely requires examining its alphabetic characters and replacing each one by the letter 3
places further or ‘right’ of it along in the alphabet, wrapping back to the beginning if necessary. A becomes
D, B becomes E, and so on up to W, which becomes Z, then the sequence continues at the beginning of the
alphabet: X becomes A, Y becomes B, and Z, becomes C. Only those 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 ROT R 3 to the input
Sample Input
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!
Sample Output
DEFGHIJKLMNOPQRSTUVWXYZABCdefghijklmnopqrstuvwxyzabc!
Problem 1032
Title: String search
Description
Input three strings s1, s2, and s3 (one for each line). They may contain whitespaces. Output the number of
times s3 and s2 occur as a substring of s1.
For example, if the input strings are “hello world”, “europe” and “wor”, then the output should be “0 1”. As
another example, if the input strings are “hello world hello”, “hello world” and “hel”, then the output should
be “1 2”. If the input strings are “hello world”, “hello” and “helo”, then the output should be “1 0”.
You are not allowed to use system functions defined in string.h.
Input
s1, s2 and s3.
Output
Two numbers.
Sample Input
Hello World! Hello
Hello
World
Sample Output
2 1
Problem 1041
Title: Dot Product of two matrices
Description
Input three positive integers n, m, and p. Then input two matrices. The first one is a n (rows) by m (columns)
matrix. The second one is a m (rows) by p (columns) matrix. Output the matrix product (should be n rows
by p columns). You are required to store the matrices in heap memory.
Input
n, m, p, and two matrices
Output
Product of these two matrices
Sample Input
4
3
2
14 9 3
2 11 15
0 12 17
5 2 3
12 25
9 10
8 5
Sample Output
273 455
243 235
244 205
102 160
Problem 1043
Title: Sort Strings
Description
Input n and then followed by n strings, one string per line. Subsequently this is followed by input m, and
then followed by m strings (one per line). Strings consist of lowercase English letters only. The maximum
string length is 100 (at most 99 letters, plus ‘\0’). However, most strings are very short. That is, you should
dynamically allocate just enough memory to store each string. You should also dynamically allocate just
enough space for storing n+m string pointers.
Please sort these n+m strings based on their lengths in descending order. String lengths are unique. There
will be no ties. Output the sorted list of strings.
Input
n and then followed by n strings. m and then followed by m strings.
Output
Sorted list, one string per line
Sample Input
5
abcdefghijk
abcde
a
abcdefgaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
zzzzzzzzzzzzzzzzzzzzzz
3
bb
cccc
hhhhhhhhhhhhhh
Sample Output
abcdefgaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
zzzzzzzzzzzzzzzzzzzzzz
hhhhhhhhhhhhhh
abcdefghijk
abcde
cccc
bb
a
Problem 1044
Title: 2 raised to the power of x
Description
2^x stands for 2 raised to the power of x. 2^4=16 and the sum of its digits is 1+6=7. 2^5=32 and the sum of
its digits is 3+2=5. Input x. x is a nonnegative integer that is at most 10000. Output the sum of the digits of
2^x.
Hint: Problem 1036 is a good start.
Input
x
Output
result (one integer)
Sample Input
4
Sample Output
7