Skip to content

Commit b26cbca

Browse files
author
Vladimir Damov
committed
adding c# advanced exam
1 parent ef7b2d6 commit b26cbca

File tree

8 files changed

+627
-0
lines changed

8 files changed

+627
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.RegularExpressions;
4+
5+
namespace DataTransfer
6+
{
7+
class DataTransfer
8+
{
9+
static void Main(string[] args)
10+
{
11+
string senderPattern = @"^s:[^;]+$";
12+
string recieverPattern = @"^r:[^;]+$";
13+
string messagePattern = @"^m--(\""[a-zA-Z\ ]+\"")$";
14+
var dataSize = 0D;
15+
var n = int.Parse(Console.ReadLine());
16+
17+
for (int i = 0; i < n; i++)
18+
{
19+
var input = Console.ReadLine().Split(';', StringSplitOptions.RemoveEmptyEntries);
20+
if (input.Length == 3)
21+
{
22+
var sender = input[0];
23+
var reciever = input[1];
24+
var message = input[2];
25+
26+
if (Regex.IsMatch(sender, senderPattern) && Regex.IsMatch(reciever, recieverPattern) && Regex.IsMatch(message, messagePattern))
27+
{
28+
var senderLetters = new List<char>();
29+
var recieverLetters = new List<char>();
30+
var msg = Regex.Match(message, messagePattern).Groups[1].Value;
31+
32+
for (int j = 2; j < sender.Length; j++)
33+
{
34+
if (char.IsDigit(sender[j]))
35+
{
36+
dataSize += char.GetNumericValue(sender[j]);
37+
}
38+
else if (char.IsLetter(sender[j]) || sender[j] == ' ')
39+
{
40+
senderLetters.Add(sender[j]);
41+
}
42+
}
43+
44+
45+
46+
for (int j = 2; j < reciever.Length; j++)
47+
{
48+
if (char.IsDigit(reciever[j]))
49+
{
50+
dataSize += char.GetNumericValue(reciever[j]);
51+
}
52+
else if (char.IsLetter(reciever[j]) || reciever[j] == ' ')
53+
{
54+
recieverLetters.Add(reciever[j]);
55+
}
56+
}
57+
58+
Console.WriteLine($"{string.Join("", senderLetters)} says {msg} to {string.Join("", recieverLetters)}");
59+
60+
}
61+
}
62+
63+
}
64+
65+
Console.WriteLine($"Total data transferred: {dataSize}MB");
66+
}
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Data Transfer
2+
3+
You will be given several lines of **messages containing data**. You have to **check for the validity of the lines**. A **valid** line should be in the format: **"s:{sender};r:{receiver};m--"{message} ""**
4+
5+
* **sender – **could contain **any ascii character except for ";"**
6+
7+
* **receiver –** could contain **any ascii character except for ";"**
8+
9+
* **message –** should contain **only letters and spaces**
10+
11+
In each valid message there is a **hidden size of data transfer.** The size of the data transfer is **calculated by the sum of all digits in the names of the sender and receiver**. After each valid message print a line in the format: "**{senderName} says "{currentMessage}" to {recieverName}". **The **printed names should contain only letters and spaces**. Example: sender “P@e$5sh#o Go^4sh5ov” is **valid **and **matches**, but when printing his name, **we only print** “Pesho Goshov”.
12+
13+
At the end print a line in the format **"Total data transferred: {totalData}MB"**.
14+
15+
## Input / Constraints
16+
17+
* First line will be a number **n** in range [1, 100].
18+
19+
* The next **n** lines will be **strings**.
20+
21+
## Output
22+
23+
* Print each valid message in the format described above.
24+
25+
* Print the total amount of data transfer.
26+
27+
## Examples
28+
29+
<table>
30+
<tr>
31+
<td>Input</td>
32+
<td>Output</td>
33+
</tr>
34+
<tr>
35+
<td>3
36+
s:P5%es4#h@o;r:G3#o!!s2h#2o;m--"Attack"
37+
s:G3er%6g43i;r:Kak€$in2% re3p5ab3lic%an;m--"I can sing"
38+
s:BABAr:Ali;m-No cave for you</td>
39+
<td>Pesho says "Attack" to Gosho
40+
Gergi says "I can sing" to Kakin repablican
41+
Total data transferred: 45MB</td>
42+
</tr>
43+
<tr>
44+
<td>5
45+
s:B^%4i35454l#$l;r:Mo5l#$34l%y;m--"Run"
46+
s:Ray;r:To^^5m;m--"Hidden Message"
47+
bla;r:1234a;m--Hello
48+
s:M#$%$#^6767687654545e;r:Yo54$#@#u5;m--"$$$"
49+
s:M#$@545e;r:You241$@#23;m"Hello"</td>
50+
<td>Bill says "Run" to Molly
51+
Ray says "Hidden Message" to Tom
52+
Total data transferred: 42MB</td>
53+
</tr>
54+
</table>
55+
56+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Tagram
6+
{
7+
class Tagram
8+
{
9+
static void Main(string[] args)
10+
{
11+
var inputs = new List<string>();
12+
13+
var input = Console.ReadLine();
14+
var tagram = new Dictionary<string, Dictionary<string, int>>();
15+
while (input != "end")
16+
{
17+
if (input.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length == 5)
18+
{
19+
inputs.Add(input);
20+
}
21+
else if (input.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length == 2)
22+
{
23+
var rem = inputs.RemoveAll(x => x.StartsWith(input.Split(' ', StringSplitOptions.RemoveEmptyEntries)[1]));
24+
}
25+
input = Console.ReadLine();
26+
}
27+
28+
for (int q = 0; q < inputs.Count; q++)
29+
{
30+
var token = inputs[q].Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();
31+
var username = token[0];
32+
var tag = token[2];
33+
var likes = int.Parse(token[4]);
34+
35+
if (!tagram.ContainsKey(username))
36+
{
37+
tagram.Add(username, new Dictionary<string, int>());
38+
}
39+
if (!tagram[username].ContainsKey(tag))
40+
{
41+
tagram[username].Add(tag, 0);
42+
}
43+
tagram[username][tag] += likes;
44+
45+
46+
47+
}
48+
49+
foreach (var users in tagram.OrderByDescending(x => x.Value.Values.Sum(g => g)).ThenBy(y => y.Value.Keys.Count))
50+
{
51+
Console.WriteLine($"{users.Key}");
52+
foreach (var kvp in users.Value)
53+
{
54+
Console.WriteLine($"- {kvp.Key}: {kvp.Value}");
55+
}
56+
}
57+
}
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Tagram
2+
3+
You will receive **several input lines** in one of the following formats:
4+
5+
* **"{username} -> {tag} -> {likes}"**
6+
7+
* **"ban {username}"**
8+
9+
The **username **and** tag **are strings. **Likes** will be an integer number. You need to keep track of **every user**.
10+
11+
When you receive a **user**, a **tag** and **likes**, register the user if **he isn't present**, **otherwise add** the tag and the likes. If the user has already used the tag just add the likes to it.
12+
13+
If you receive **"ban {username}"** and **the username exists**, remove him from the database.
14+
15+
You should end your program when you receive the command **"end"**. At that point you should print the users, **ordered by total likes in desecending order, then ordered by the tags’ count in ascending order**. **Foreach** player print their tag and likes.
16+
17+
## Input / Constraints
18+
19+
* The input comes in the form of commands in one of the formats specified above.
20+
21+
* Username and tag **will always be one word string, containing no whitespaces**.
22+
23+
* Likes will be an **integer** in the **range [0, 1000]**.
24+
25+
* There will be **no invalid** input lines.
26+
27+
* The programm ends when you receive the command **"end"**.
28+
29+
## Output
30+
31+
* The output format for each player is:
32+
33+
**"{username}"**
34+
35+
**"- {tag}: {likes}"**
36+
37+
## Examples
38+
39+
<table>
40+
<tr>
41+
<td>Input</td>
42+
<td>Output</td>
43+
</tr>
44+
<tr>
45+
<td>Katty -> healthy -> 50
46+
Elvin -> food -> 20
47+
John -> music -> 30
48+
Katty -> fitness -> 100
49+
end</td>
50+
<td>Katty
51+
- healthy: 50
52+
- fitness: 100
53+
John
54+
- music: 30
55+
Elvin
56+
- food: 20</td>
57+
</tr>
58+
<tr>
59+
<td>Input</td>
60+
<td>Output</td>
61+
</tr>
62+
<tr>
63+
<td>Monica -> music -> 100
64+
Monica -> dance -> 50
65+
John -> chill -> 200
66+
Santa -> angry -> 300
67+
ban Santa
68+
Joshua -> football -> 500
69+
end</td>
70+
<td>Joshua
71+
- football: 500
72+
John
73+
- chill: 200
74+
Monica
75+
- music: 100
76+
- dance: 50</td>
77+
</tr>
78+
<tr>
79+
<td>Ani -> A1 -> 100
80+
Bobi -> B2 -> 100
81+
Bobi -> BB2 -> 150
82+
Ani -> AA1 -> 100
83+
Ani -> AAA1 -> 50
84+
end</td>
85+
<td>Bobi
86+
- B2: 100
87+
- BB2: 150
88+
Ani
89+
- A1: 100
90+
- AA1: 100
91+
- AAA1: 50</td>
92+
</tr>
93+
</table>
94+
95+

0 commit comments

Comments
 (0)