CSharp-Advanced-LINQ-Exercises
CSharp-Advanced-LINQ-Exercises
This document defines the exercise assignments for the "CSharp Advanced" course @ Software University. Please
submit your solutions (source code) of all below described problems in Judge.
Examples
Input Output
Sara Mills 1 Andrew Gibson
Andrew Gibson 2 Andrew Carter
Craig Ellis 1 Steven Cole
Steven Cole 2
Andrew Carter 2
END
Examples
Input Output
Sara Mills Andrew Gibson
Andrew Gibson Craig Ellis
Craig Ellis Andrew Carter
Steven Cole
Andrew Carter
END
Examples
Input Output
Sara Mills 24 Sara Mills 24
Andrew Gibson 21 Andrew Gibson 21
Craig Ellis 19 Craig Ellis 19
Steven Cole 35
Andrew Carter 15
END
Problem 4. Sort Students
Using the lambda expressions with LINQ syntax sort the students first by last name in ascending order and then by
first name in descending order.
Examples
Input Output
Sara Gibson Steven Cole
Andrew Gibson Craig Ellis
Craig Ellis Andrew Ellis
Steven Cole Sara Gibson
Andrew Ellis Andrew Gibson
END
Examples
Input Output
Sara Mills [email protected] Sara Mills
Andrew Gibson [email protected] Andrew Carter
Craig Ellis [email protected]
Steven Cole [email protected]
Andrew Carter [email protected]
END
Examples
Input Output
Sara Mills 02435521 Sara Mills
Andrew Gibson 0895223344 Craig Ellis
Craig Ellis +3592667710
Steven Cole 3242133312
Andrew Carter +001234532
END
Examples
Input Output
Sara Mills 6 6 6 5 Sara Mills
Andrew Gibson 3 4 5 6 Andrew Gibson
Craig Ellis 4 2 3 4 Steven Cole
Steven Cole 5 6 5 5
Andrew Carter 5 3 4 2
END
Examples
Input Output
Sara Mills 6 6 6 5 Craig Ellis
Andrew Gibson 3 4 5 6 Andrew Carter
Craig Ellis 4 2 3 4
Steven Cole 5 6 5 5
Andrew Carter 5 3 4 2
END
Examples
Input Output
554214 6 6 6 5 6 6 6 5
653215 3 4 5 6 3 4 5 6
156212 4 2 3 4 5 3 4 2
324413 5 6 5 5
134014 5 3 4 2
END
Examples
Input Output
Ivaylo Petrov 10 3 - Stanimir Svilianov, Indje
Stanimir Svilianov 3 Kromidov
Indje Kromidov 3 4 - Irina Balabanova
Irina Balabanova 4 10 - Ivaylo Petrov
END
Problem 11. Students Joined to Specialties
Create a new class StudentSpecialty that holds specialty name and faculty number. Create a Student class that
holds student name and faculty number. Create a list of student specialties, where each specialty corresponds to a
certain student (via the faculty number). You will recieve several specialties in the format :
Until you reach "Students:" , you should add specialties to the collection. After you reach "Students:", you should
start reading students in the format :
You should add the students untill you recieve "END" command.
Print all student names alphabetically along with their faculty number and specialty name. Use the "join" LINQ
operator.
Examples
Student Specialties Students Result (Joined Students with Specialties)
SpecialtyName FacNum FacNum Name Name FacNum Specialty
Web Developer 203314 215314 Milena Kirova Asya Manova 203314 Web Developer
Web Developer 203114 203114 Stefan Popov Asya Manova 203314 QA Engineer
join →
PHP Developer 203814 203314 Asya Manova Diana Petrova 203914 PHP Developer
PHP Developer 203914 203914 Diana Petrova Diana Petrova 203914 Web Developer
QA Engineer 203314 203814 Ivan Ivanov Ivan Ivanov 203814 PHP Developer
Web Developer 203914 Stefan Popov 203114 Web Developer
Input Output
Web Developer 203314 Asya Manova 203314 Web Developer
Web Developer 203114 Asya Manova 203314 QA Engineer
PHP Developer 203814 Diana Petrova 203914 PHP Developer
PHP Developer 203914 Diana Petrova 203914 Web Developer
QA Engineer 203314 Ivan Ivanov 203814 PHP Developer
Web Developer 203914 Stefan Popov 203114 Web Developer
Students:
215314 Milena Kirova
203114 Stefan Popov
203314 Asya Manova
203914 Diana Petrova
203814 Ivan Ivanov
END
As you probably know Little John is the right hand of the famous English hero - Robin Hood. A little known fact is
that Little John can't handle Math very well. Before Robin Hood left to see Marry Ann, he asked John to count his
hay of arrows and send him an encrypted message containing the arrow's count. The message should be encrypted
since it can be intercepted by the Nottingham’s evil Sheriff. Your task is to help Little John before it is too late (0.10
sec).
You are given 4 input strings (a hay). Those strings may or may not contain arrows. The arrows can be of different
type as follows:
After you find the count of each arrow type you should concatenate them into one number in the order: small,
medium, large arrow (even if the arrow count is 0). Then you convert the number in binary representation, reverse
it and concatenate it again with the initial binary representation of the number. You convert the final binary
number again back to decimal. This is the encrypted message you should send to Robin Hood.
Input
The input will be read from the console. The data will be received from 4 input lines containing strings.
Output
The output should be a decimal number, representing the encrypted count of arrows.
Constraints
● The input strings will contain any ASCII character.
● Allowed working time: 0.1 seconds. Allowed memory: 16 MB.
Examples
Input Output
>>>----->>abc>>>----->> 14535
>>>----->>
>----->s The count is: 1 small, 1 medium and 3 large arrows
>>-----> 113(dec) = 1110001(bin) -> reversed is
1000111(bin)
11100011000111(bin) = 14535(dec)
Input
The input comes from the console. At the first line the number n stays alone. At the next n lines, we have n orders in
format |<company> - <amount> - <product>|.
The input data will always be valid and in the format described. There is no need to check it explicitly.
Output
Print one line for each company. Company lines should be ordered in alphabetical order. For each company print
the products ordered by this company in order of appearance, along with the total amount for the given product.
Each line should be in format <company>: <product>-<amount>, <product>-<amount>, … <product>-<amount>
Constraints
● The count of the lines n will be in the range [1 … 100].
● The <company> and <product> will consist only of Latin characters, with length of [1 … 20].
● The <amount> will be an integer number in the range [1 … 1000].
● Time limit: 0.1 sec. Memory limit: 16 MB.
Examples
Input Output Input Output
7 SoftUni: paper- 5 SoftUni:
|SoftUni - 600 - paper| 600, chair-40, |SoftUni - 200 - desk| desk-400,
|Vivacom - 600 - pen| printer-1 |SoftUni - 40 - PC| PC-40,
|XS - 20 - chair| |SoftUni - 200 - desk| paper-600,
|Vivacom - 200 - chair| Vivacom: pen- |SoftUni - 600 - paper|
600, chair-200 textbook-
|SoftUni - 40 - chair| |SoftUni - 600 - 600
|XS - 40 - chair| XS: chair-60 textbook|
|SoftUni - 1 - printer|
You are given as input course data about 1000 students in a .txt file (tab-separated values). Each line in the input
holds ID, first name, last name, email, gender, student type, exam result, homework sent, homework evaluated,
teamwork score, attendances count, bonus.