Complete the zip and unzip funciton:
#include "function.h"
#include <stdlib.h>
List* zip(List *lptr1, List *lptr2)
{
/*your code here*/
}Pair* unzip(List *lptr)
{
/*your code here*/
}
What zip does is to combine 2 lists.
Elements in corresponding positions form a pair.
Zip function takes the 2 lists as inputs and generates a new list including all the pairs. (2 lists -> a list of pairs)
Note: [ ] means a list, ( ) means a pair
e.g.
input 1: [1,2,3]
input 2: ["a","b","c"]
After zip: [(1,"a"),(2,"b"),(3,"c")]
If we zip the result with input 2 again:
[("a",(1,"a")),("b",(2,"b")),("c",(3,"c"))]
If we zip the first result with the 2nd result together:
[((1,"a"),("a",(1,"a"))),((2,"b"),("b",(2,"b"))),((3,"c"),("c",(3,"c")))]
What unzip does is to transform a list of pairs to a pair of lists.
e.g.
input: [(1,"a"),(2,"b"),(3,"c")]
unzip: ([1,2,3],["a","b","c"])
input: [("a",(1,"a")),("b",(2,"b")),("c",(3,"c"))]
unzip: (["a","b","c"],[(1,"a"),(2,"b"),(3,"c")])
What we have to do in this problem,
is to zip 2 lists N times and do unzip 1 time to output the final pair.
5 lines
1st line: M1 (number of 1st list's elements)
2nd line: M1 elements of 1st list
3rd line: M2 (number of 2nd list's elements)
4th line: M2 elements of 2nd list
5th line: N (times to do zip)
One line. The final result of pair after N times of zip and 1 time of unzip. Remeber the new line in the end.