Laboratory 5 - Exercises

Comparison instructions, conditional jumps, loop instructions. String operations.

Exercises

  1. Given a byte string S of length l, obtain the string D of length l-1 as D(i) = S(i) * S(i+1) (each element of D is the product of two consecutive elements of S).
    Example:
    S: 1, 2, 3, 4
    D: 2, 6, 12
    
  2. Given a character string S, obtain the string D containing all special characters (!@#$%^&*) of the string S.
    Example:
    S: '+', '4', '2', 'a', '@', '3', '$', '*'
    D: '@','$','*'
    
  3. Two byte strings S1 and S2 are given. Obtain the string D by concatenating the elements of S1 from the left hand side to the right hand side and the elements of S2 from the right hand side to the left hand side.
    Example:
    S1: 1, 2, 3, 4
    S2: 5, 6, 7
    D: 1, 2, 3, 4, 7, 6, 5
    
  4. Two byte strings S1 and S2 are given, having the same length. Obtain the string D in the following way: each element found on the even positions of D is the sum of the corresponding elements from S1 and S2, and each element found on the odd positions of D is the difference of the corresponding elements from S1 and S2.
    Example:
    S1: 1, 2, 3, 4
    S2: 5, 6, 7, 8
    D: 6, -4, 10, -4
    
  5. A character string S is given. Obtain the string D containing all small letters from the string S.
    Example:
    S: 'a', 'A', 'b', 'B', '2', '%', 'x'
    D: 'a', 'b', 'x'
    
  6. A byte string S is given. Obtain the string D by concatenating the elements found on the even positions of S and then the elements found on the odd positions of S.
    Example:
    S: 1, 2, 3, 4, 5, 6, 7, 8
    D: 1, 3, 5, 7, 2, 4, 6, 8
    
  7. Two byte string S1 and S2 are given, having the same length. Obtain the string D by intercalating the elements of the two strings.
    Example:
    S1: 1, 3, 5, 7
    S2: 2, 6, 9, 4
    D: 1, 2, 3, 6, 5, 9, 7, 4
    
  8. A character string S is given. Obtain the string D that contains all capital letters of the string S.
    Example:
    S: 'a', 'A', 'b', 'B', '2', '%', 'x', 'M'
    D: 'A', 'B', 'M'
    
  9. A byte string S of length l is given. Obtain the string D of length l-1 so that the elements of D represent the difference between every two consecutive elements of S.
    Example:
    S: 1, 2, 4, 6, 10, 20, 25
    D: 1, 2, 2, 4, 10, 5
    
  10. Two character strings S1 and S2 are given. Obtain the string D by concatenating the elements of S2 in reverse order and the elements found on even positions in S1.
    Example:
    S1: '+', '2', '2', 'b', '8', '6', 'X', '8'
    S2: 'a', '4', '5'
    D: '5', '4', 'a', '2','b', '6', '8'
    
  11. A byte string S is given. Obtain the string D1 which contains all the even numbers of S and the string D2 which contains all the odd numbers of S.
    Example:
    S: 1, 5, 3, 8, 2, 9
    D1: 8, 2
    D2: 1, 5, 3, 9
    
  12. Two character strings S1 and S2 are given. Obtain the string D by concatenating the elements found on even positions in S2 and the elements found on odd positions in S1.
    Example:
    S1: 'a', 'b', 'c', 'd', 'e', 'f'
    S2: '1', '2', '3', '4', '5'
    D: '2', '4','a','c','e'
    
  13. A byte string S is given. Obtain the string D1 which contains the elements found on the even positions of S and the string D2 which contains the elements found on the odd positions of S.
    Example:
    S: 1, 5, 3, 8, 2, 9
    D1: 1, 3, 2
    D2: 5, 8, 9
    
  14. A byte string S is given. Obtain the string D1 which contains all the positive numbers of S and the string D2 which contains all the negative numbers of S.
    Example:
    S: 1, 3, -2, -5, 3, -8, 5, 0
    D1: 1, 3, 3, 5, 0
    D2: -2, -5, -8
    
  15. Two byte strings A and B are given. Obtain the string R by concatenating the elements of B in reverse order and the odd elements of A.
    Example:
    A: 2, 1, 3, 3, 4, 2, 6
    B: 4, 5, 7, 6, 2, 1
    R: 1, 2, 6, 7, 5, 4, 1, 3, 3
    
  16. Two character strings S1 and S2 are given. Obtain the string D by concatenating the elements found on odd positions in S2 and the elements found on even positions in S1.
    Example:
    S1: 'a', 'b', 'c', 'b', 'e', 'f'
    S2: '1', '2', '3', '4', '5'
    D: '1', '3', '5', 'b', 'b', 'f'
    
  17. Two byte strings S1 and S2 are given, having the same length. Obtain the string D so that each element of D represents the maximum of the corresponding elements from S1 and S2.
    Example:
    S1: 1, 3, 6, 2, 3, 7
    S2: 6, 3, 8, 1, 2, 5
    D: 6, 3, 8, 2, 3, 7
    
  18. Two byte strings A and B are given. Obtain the string R that contains only the odd positive elements of the two strings.
    Example:
    A: 2, 1, 3, -3
    B: 4, 5, -5, 7
    R: 1, 3, 5, 7
    
  19. Two byte strings A and B are given. Obtain the string R that contains only the even negative elements of the two strings.
    Example:
    A: 2, 1, 3, -3, -4, 2, -6
    B: 4, 5, -5, 7, -6, -2, 1
    R: -4, -6, -6, -2
    
  20. Two byte strings A and B are given. Obtain the string R by concatenating the elements of B in reverse order and the even elements of A.
    Example:
    A: 2, 1, 3, 3, 4, 2, 6
    B: 4, 5, 7, 6, 2, 1
    R: 1, 2, 6, 7, 5, 4, 2, 4, 2, 6
    
  21. Two byte strings A and B are given. Obtain the string R by concatenating the elements of B in reverse order and the negative elements of A.
    Example:
    A: 2, 1, -3, 3, -4, 2, 6
    B: 4, 5, 7, 6, 2, 1
    R: 1, 2, 6, 7, 5, 4, -3, -4
    
  22. Two byte strings S1 and S2 of the same length are given. Obtain the string D where each element contains the minimum of the corresponding elements from S1 and S2.
    Example:
    S1: 1, 3, 6, 2, 3, 7
    S2: 6, 3, 8, 1, 2, 5
    D: 1, 3, 6, 1, 2, 5
    
  23. A byte string S is given. Obtain in the string D the set of the elements of S.
    Example:
    S: 1, 4, 2, 4, 8, 2, 1, 1
    D: 1, 4, 2, 8
    
  24. Two byte strings A and B are given. Obtain the string R by concatenating the elements of B in reverse order and the elements of A in reverse order.
    Example:
    A: 2, 1, -3, 0
    B: 4, 5, 7, 6, 2, 1
    R: 1, 2, 6, 7, 5, 4, 0, -3, 1, 2
    
  25. Two character strings S1 and S2 are given. Obtain the string D which contains all the elements of S1 that do not appear in S2.
    Example:
    S1: '+', '4', '2', 'a', '8', '4', 'X', '5'
    S2: 'a', '4', '5'
    D: '+', '2', '8', 'X'
    
  26. A byte string S is given. Obtain the maximum of the elements found on the even positions and the minimum of the elements found on the odd positions of S.
    Example:
    S: 1, 4, 2, 3, 8, 4, 9, 5
    max_poz_pare: 9
    min_poz_impare: 3
    
  27. Two byte strings S1 and S2 of the same length are given. Obtain the string D where each element is the difference of the corresponding elements from S1 and S2
    Example:
    S1: 1, 3, 6, 2, 3, 2
    S2: 6, 3, 8, 1, 2, 5
    D: -5, 0, -2, 1, 1, -3
    
  28. Two character strings S1 and S2 are given. Obtain the string D by concatenating the elements found on the positions multiple of 3 from S1 and the elements of S2 in reverse order.
    Example:
    S1: '+', '4', '2', 'a', '8', '4', 'X', '5'
    S2: 'a', '4', '5'
    D: '+', 'a', 'X', '5', '4', 'a'
    
  29. A byte string S is given. Build the string D whose elements represent the sum of each two consecutive bytes of S.
    Example:
    S: 1, 2, 3, 4, 5, 6
    D: 3, 5, 7, 9, 11
    
  30. Two byte strings S1 and S2 of the same length are given. Obtain the string D where each element is the sum of the corresponding elements from S1 and S2
    Example:
    S1: 1, 3, 6, 2, 3, 2
    S2: 6, 3, 8, 1, 2, 5
    D: 7, 6, 14, 3, 5, 7
    
  31. A character string S is given. Obtain the string D which contains all the digit characters of S.
    Example:
    S: '+', '4', '2', 'a', '8', '4', 'X', '5'
    D: '4', '2', '8', '4', '5'
    
  32. A byte string S of length l is given. Obtain the string D of length l-1, such that each element of D is the quotient of two consecutive elements of S, i.e. D(i) = S(i) / S(i+1).
    Example:
    S: 1, 6, 3, 1
    D: 0, 2, 3