Consider this data sequence: "fish bird reptile reptile bird bird bird mammal fish". let's define a singleton to be a data element that is not repeated immediately before or after itself in the sequence. so, here there are four singletons (the first appearance of "fish", the first appearance of "bird", "mammal", and the second appearance of "fish"). write some code that uses a loop to read a sequence of words, terminated by the "xxxxx". the code assigns to the variable n the number of singletons that were read. (for example in the above data sequence it would assign 4 to n. assume that n has already been declared . but not initialized . assume that there will be at least one word before the terminating "xxxxx".

Respuesta :

n = 0

string temp;
if wordset[0] != wordset[1] then {
    n = n + 1
}
temp = wordset[0]
for i = 1 to wordset.length - 2 do {
    if wordset[i] != temp AND wordset[i] != wordset[i + 1] then {
        n = n + 1
    }
    temp = wordset[i]
 


}