Difficult tasks
Some difficult tasks will be added here.
- (vector | array) Remove all odd elements from the given vector by shifting the remaining elements to its beginning.
Project "Normal Algorithms"
Description of the subject area:
1.A normal substitution is a pair of strings S, P together with a final flag. A substitution is said to be applicable to a given string X if S is a substring of it. Substitution is applied to string X by replacing the first occurrence of the substring S with P.
2.A normal algorithm scheme is a normal permutation vector.
3.A normal algorithm step is the application of an algorithm scheme to a given string according to the following rules:
- The first substitution applicable to the string is found.
- The substitution found is applied to the string.
4.A normal algorithm is a multiple repetition of the steps of a normal algorithm. The execution of the algorithm ends in the following cases:
- Final substitution applied (substitution with the final flag set).
- None of the schema substitutions apply to the current row.
Examples:
1.Let there be a schema {{"ab", "", false}
, {"a", "b", false}}
. As a result of its application to the word aababab
, we get the following chain of transformations: aababab ==> aabab ==> aab ==> a ==> b
. The first three steps of the normal algorithm consist of applying the first substitution, and in the fourth step, the second substitution is applied (the first is no longer applicable). The fourth step turns out to be the last, since after it none of the substitutions is applicable (the first case of completion of the normal algorithm).
2.Scheme {{"b", "a", true}
, {"a", "b", false}}
on line aaa gives: aaa ==> baa ==> aaa
. In the second step, the first (final) substitution is applied, so the normal algorithm ends.
The task:
1.Describe a structure for storing normal substitution.
2.Define a function that applies a given normal algorithm scheme (substitution vector) to a given string using helper functions.
3.Check the operation of the function using the above examples and several of your own.
4.Check what happens when the schema {{"a", "b", false}
, {"b", "a", false}}
is applied to the string "aabb
".
- (lists | files) In a text file there is an information about the results of the student exams. The info contains the last name, first name, and mark in 5 subjects for each student . There are no more than 20 students in a group.
Write a program that provides the following information:
- list of students (full name);
- list of students who passed all exams with 5 mark;
- a list of students who have at least one 3 mark in exams;
- a list of students who have 2 mark. If a student has more than one 2 mark, he is excluded from the list.