## 1. Course based discussions (30 minutes)

- Pointers and arrays
- Linking pointers to arrays, pointer arithmetics
- Character arrays
- Examples

## 2. Exercises (70 minutes)

**Warning!** For every function or group functions from the exercises below, a test will be made, in the *main *function. Students can choose at most one exercise that has the score less than 0.90 points.

The following declarations are given:

#define MAX_ARRAY_LENGTH 100 #define MAX_ARRAY_LENGTH_LONG 1000 struct vector { unsigned int length; int values[MAX_ARRAY_LENGTH]; }; struct matrix { unsigned int lines; unsigned int columns; unsigned int values[MAX_ARRAY_LENGTH][MAX_ARRAY_LENGTH]; }; struct smaze { char maze[MAX_ARRAY_LENGTH_LONG][MAX_ARRAY_LENGTH_LONG]; unsigned int noOfRows; int noOfColumns; unsigned int rowOfDeparture; unsigned int columnOfDeparture; unsigned int rowOfExit; unsigned int columnOfExit; };

**Vector exercises**

- (1,00p) Write a function that receives
- a vector with
*n*numbers, whose binary representations depict sets of numbers in the range of [0,63]. For example, the binary codification 00100011 (on 8 bit), corresponding to the decimal number 35, represents the set {0,1,5} (the bits set on 1). - a vector with n-1 characters, each character represents an operation between sets: ’U’ = union, ’A’ = intersection, ’\’ = A – B, ’/’ = B – A and returns the number resulted from applying the operations on the received numbers as parameters as follows:
- The first operation is applied on the first two numbers
- The second operation is applied on the previous operation’s result and the third number
- The third operation is applied on the previous operation’s result and the fourth number
- etc.

Ex: For sets=[1,2,3] and operations=[’U’,’\’] the function will compute 001(1) union with 010(2) and it will have the result 011 and 011 minus 011(3) will have the result 000(0) and the function will return 0.

*unsigned long setOperations(long sets[], char operations[], unsigned int x);*

- a vector with
- (0.50p) Write a function which, for a vector of length
*n*verifies if the elements from the vector are the first*n*numbers of the Fibonnaci sequence. Ex: For [0,1,1,2,3,4] the function will return true;

For[0,1,1,3,2,4] and [0,1,1,2,4] the function will return false.

*bool areOrderedFibonnaci(vector);* - (0.50p)Write a function that receives two vectors as parameters and returns 0 if they are equal, 1 if the first is included in the second, 2 if the second is included in the first, and 3 otherwise.

Ex: For [1,2,3] and [3,1,2] the function returns 0;

For [1,2,3] and[3,2] the function returns 2;

For [1,2,3] and [3,2,4] the function returns 3.

*unsigned char checkVectorInclude(vector vecOne, vector vecTwo);* - (0.50p) Write a function that for a vector of length
*n*and a number*a*, verifies if the elements from the vector are the first*n*numbers of the Fibonnaci sequence starting with the number*a*(>=2).

Ex: For vector [3,5,2] of length*n*=3 and number*a*=2 the function will return*true*;

For vector of length 3 [3,4,2] and number*a*=2 the function will return*false*.

*bool isPartOfFibonnaci(vector vec, unsigned int startingNumber);* - (0.60p) Write a function that receives as parameters, a vector of
*n*numbers and a vector of*n-1*characters representing bit-operations, and returns the result of applying the operations on numbers. The operations are applied as follows: the first operation is applied on the first two numbers, the second operation is applied on the first operation’s result and the third number, the third operation is applied on the second operation’s result and the fourth number etc.

*unsigned long bitOperations(long numbers[], char operations[], unsigned int x);* - (0.25p) A vector
*x*with*n*integer number is read. Rearrange the elements from*x*so that the negative elements to appear first, then the positive ones, keeping the order of both negative and positive numbers (O(n)). - (0,75p) A vector
*a*with*n*integer numbers is read,*n<1001*. Compute*s*= the maximum sum that can be obtained from a sequence of elements on consecutive positions.

Example: n=9, a=[-2,1,-3,4,-1,2,1,-5,4]. The result will be s=6.

**B. Matrix exercises**

- (0.50p) Write a function that receives as parameter a square matrix
*n*n*, a number of left rotations and a number of right rotations and returns the resulted matrix after the left and right rotations.

*matrix rotate(matrix mat, unsigned int rotLeft, unsigned int rotRight);* - (0,90p) Write a function that receives as parameter a matrix with
*m*rows and*n*columns and verifies if the matrix contains the first*(m***n*) elements from the Fibonnaci sequence in spiral, starting from the upper left corner.

Ex: For [0,1] [2,1] and [0, 1, 1] [13,21,2] [8, 5, 3] returns true; For [0,1] [1,2] returns false.

*bool fibonnaciSpirale(matrix);* - (0,60p) Write a function that receives a matrix of 1 and 0’s and returns the matrix modified as follows: if in a cell 0 is found, that row and column will be filled with 0. Ex: For matrix [1, 0, 1] [1, 1, 1] [1, 1, 1] the function will return [0, 0, 0] [1, 0, 1] [1, 0, 1]

*void transformMatrix(matrix mat);* - (1,00p) Write a function that receives a maze in the form of a matrix, the position of the starting cell and the position of the exit cell and returns the minimum length of the path from start to exit. Each cell from the matrix will have a value 1(wall) or 0 (road).

*unsigned int minRouteLength(maze magicMaze);* - (0.25p each) Write a function that will calculate:
- the sum of the elements under the diagonal of a square matrix;
- the sum of the elements on a row of a matrix;
- the sum of elements in a matrix, except a column.

- (0.25p each) Exercises with character arrays (for example rewriting functions from <string.h>)
- (0.50p) Write a function which for a received vector and matrix as parameters, it verifies if the vector is found as row/column in the matrix.

*bool checkIsIn(vector vec, matrix mat);*

**C. Exercises with character arrays**

- (1,00p) Write a function that divides a romanian word into syllables, applying the rules from http://www.limba-romana.net/lectie/Reguli-de-despartire-a-cuvintelor-in-silabe/72/
- (0,50p) Write a function that receives a character array using HTML tags for
**bold**,*italic*and underline and it removes them. - (1,50p) Write a function that codifies a natural number in the range 0 and 100000000 in a character array, representing the number written with letters, in Romanian/English. For example, for the number 70054, the result of the function will be „saptezecidemiicincizecisipatru” (seventythousandfiftyfour).
- (1,50p) Write a function that codifies a natural number in the range 0 and 100000 in a character array, representing the number written with letters, in French. For example, for 74392, the result will be „soixante-quatorze mille trois cent quatre-vingt-douze”. For rules http://www.heartandcoeur.com/convert/convert_chiffre_lettre.php
- (0,75p) Write a function that receives a text in the form of a character array and returns a vector of structures of type
*struct { char word[100]; unsigned int nrAppearances; }*with the words from text, as well as the number of appearances of each word. Any letter sequence (capital or not), digits or hyphen symbol (represented by „-„(minus)) is considered a word, the rest being considered as separators. - (1,00p) A left aligned text is given, which has words (composed by capital/noncapital letters, „-” symbol (hyphen=minus) and symbols ” „(space) or punctuation marks from Romanian). Align the text to right, removing double spaces between words if necessary.
- (1,00p) For representing the location of a chess piece on a chess table, a 4 characters array codification is considered. The first character represents the piece colour, the second character depicts the piece type, the third – the line, the fourth- the column. Write a function that verifies if a certain piece attacks or not another piece.