A company of electronic equipment is developing a system lighting. Since more than one team of people committed to the development, they have agreed an interesting interface between developers of the LEDs and those who perform the ignition control: in a circumference of the plaquette of control are determined points which correspond to the different LEDs or to the power switch. This setup allows some flexibility, but they have realized that they now need to determine how to connect these points (always a LED with a control), and to do this they must decide which to join. One complication is that these unions can not cross because it would make a short-circuit, and it is necessary to maximize the number of LEDs that will work! Yes, it is unbelievable but there could be more (or less) LEDs than checkpoints. To help them you must write a function: connect (chain, pairs) where: chain is a secuence of more than 1000 letter "L" or "C" representing the order and function of the points in the circumference. The numeration of the points starts in 1 pairs is a vector of ints where is the conections are hold, always placing the point C in front of their corresponding point L The function returns an int: the number of the conections that could be established and held in ' connect ' Example: If chain had: LLLLCCCLC The function would return a 4 and pairs could contain: 5 3 7 8 6 2 9 1 Implementation: int connect( (char chain[], int pairs[ ]); |
______ | __ | | || | LLLLCCCLC | | | | | ———— | ————————— |
If chain had: LLLLCCCLC The function would return a 4 and pairs could contain: 5 3 7 8 6 2 9 1 |
pairs could contain |
_________ | ___ __| | | | ||| LLLLCCCLC | | ————— |
4 5 3 6 2 7 1 9 |