0% found this document useful (0 votes)
2 views

Quiz - 1 String Array

Uploaded by

mineonate08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Quiz - 1 String Array

Uploaded by

mineonate08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Exercise – 1

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)
{

public static string LogLevel(string logLine)


{

public static string Reformat(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.

"AABCCCDEEEE" -> "2AB3CD4E" -> "AABCCCDEEEE"


For simplicity, you can assume that the unencoded string will only contain the letters A through Z
(either lower or upper case) and whitespace. This way data to be encoded will never contain any
numbers and the numbers inside data to be decoded always represent the count for the following
character.

Given Program
public static class RunLengthEncoding
{
public static string Encode(string input)
{

public static string Decode(string input)


{

}
}

2|Page
Exercise - 3
Instructions: Convert a phrase to its acronym.

Techies love their TLA (Three Letter Acronyms)!

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;

public static class Acronym


{
public static string Abbreviate(string phrase)
{

}
}

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:

For want of a nail, the shoe was lost.


For want of a shoe, the horse was lost.
For want of a horse, the rider was lost.
For want of a rider, the message was lost.
For want of a message, the battle was lost.
For want of a battle, the kingdom was lost.
And all for the want of a nail.

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;

public static class Proverb


{
public static string[] Recite(string[] subjects)
{

}
}

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;

public class Anagram


{
public Anagram(string baseWord)
{

public string[] FindAnagrams(string[] potentialMatches)


{

}
}

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:

Each resistor has a resistance value.


Resistors are small - so small in fact that if you printed the resistance value on them, it would be
hard to read.
To get around this problem, manufacturers print color-coded bands onto the resistors to denote their
resistance values. Each band has a position and a numeric value.

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!

The band colors are encoded as follows:

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;

public static class ResistorColorDuo


{
public static int Value(string[] colors)
{

}
}

6|Page

You might also like