Quiz - 1 String Array
Quiz - 1 String Array
Instructions
In this exercise, you'll be processing log-lines.
Each log line is a string formatted as follows: "[<LEVEL>]: <MESSAGE>".
There are three different log levels:
INFO
WARNING
ERROR
You have three tasks, each of which will take a log line and ask you to do something with it.
Task 1: Get a message from a log line
Implement the (static) LogLine.Message() method to return a log line's message:
LogLine.Message("[ERROR]: Invalid operation")
// => "Invalid operation"
Any leading or trailing white space should be removed:
LogLine.Message("[WARNING]: Disk almost full\r\n")
// => "Disk almost full"
Task 2: Get log level from a log line
Implement the (static) LogLine.LogLevel() method to return a log line's log level, which should be
returned in lowercase:
LogLine.LogLevel("[ERROR]: Invalid operation")
// => "error"
Task 3: Reformat a log line
Implement the (static) LogLine.Reformat() method that reformats the log line, putting the message
first and the log level after it in parentheses:
LogLine.Reformat("[INFO]: Operation completed")
// => "Operation completed (info)"
Given Program
using System;
static class LogLine
{
public static string Message(string logLine)
{
}
}
1|Page
Exercise - 2
Instructions: Implement run-length encoding and decoding.
Run-length encoding (RLE) is a simple form of data compression, where runs (consecutive data
elements) are replaced by just one data value and count.
For example, we can represent the original 53 characters with only 13.
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWW
WWWWWWWWWWWWB" "12WB12W3B24WB"
RLE allows the original data to be perfectly reconstructed from the compressed data, which makes
it a lossless data compression.
Given Program
public static class RunLengthEncoding
{
public static string Encode(string input)
{
}
}
2|Page
Exercise - 3
Instructions: Convert a phrase to its acronym.
Help generate some jargon by writing a program that converts a long name like Portable Network
Graphics to its acronym (PNG).
Punctuation is handled as follows: hyphens are word separators (like whitespace); all other
punctuation can be removed from the input.
For example:
Input Output
As Soon As Possible ASAP
Liquid-crystal display LCD
Thank George It's Friday! TGIF
Given Program
using System;
}
}
3|Page
Exercise - 4
Instructions:
For want of a horseshoe nail, a kingdom was lost, or so the saying goes.
Given a list of inputs, generate the relevant proverb. For example, given the list ["nail", "shoe",
"horse", "rider", "message", "battle", "kingdom"], you will output the full text of this proverbial
rhyme:
Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length
and content. No line of the output text should be a static, unchanging string; all should vary
according to the input given.
Try to capture the structure of the song in your code, where you build up the song by composing its
parts.
Given Program
using System;
}
}
4|Page
Exercise - 5
Instructions:
An anagram is a rearrangement of letters to form a new word: for example "owns" is an anagram
of "snow". A word is not its own anagram: for example, "stop" is not an anagram of "stop".
Given a target word and a set of candidate words, this exercise requests the anagram set: the
subset of the candidates that are anagrams of the target.
The target and candidates are words of one or more ASCII alphabetic characters (A-Z and a-z).
Lowercase and uppercase characters are equivalent: for example, "PoTS" is an anagram of "sTOp",
but StoP is not an anagram of sTOp. The anagram set is the subset of the candidate set that are
anagrams of the target (in any order). Words in the anagram set should have the same letter case
as in the candidate set.
Given the target "stone" and candidates "stone", "tones", "banana", "tons", "notes", "Seton", the
anagram set is "tones", "notes", "Seton".
Given Program
using System;
}
}
5|Page
Exercise - 6
Instructions:
If you want to build something using a Raspberry Pi, you'll probably use resistors. For this exercise,
you need to know two things about them:
The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number.
For example, if they printed a brown band (value 1) followed by a green band (value 5), it would
translate to the number 15.
In this exercise, you are going to create a helpful program so that you don't have to remember the
values of the bands. The program will take color names as input and output a two digit number,
even if the input is more than two colors!
Black: 0
Brown: 1
Red: 2
Orange: 3
Yellow: 4
Green: 5
Blue: 6
Violet: 7
Grey: 8
White: 9
From the example above: brown-green should return 15 brown-green-violet should return 15 too,
ignoring the third color.
Given Program
using System;
}
}
6|Page