2012-10-28, 08:55 PM
This works fine. Unless I misunderstood your problem.
You can replace vector with an array if you haven't learned it yet.
You can replace vector with an array if you haven't learned it yet.
Code:
#include <iostream>
#include <vector>
/*
"Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8".
Any value that is the same as the immediately preceding value is considered a CONSECUTIVE DUPLICATE.
In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6.
Note that the last 3 is not a consecutive duplicate because it was preceded by a 7.
*/
int main() {
std::vector<int> holder;
size_t total = 0;
int a = 0;
while(std::cin >> a) {
holder.push_back(a);
if(a < 0)
break;
}
for(size_t i = 1; i < holder.size(); ++i) {
if(holder[i] == holder[i-1])
++total;
}
std::cout << "Total consecutives: " << total;
std::cin.get();
std::cin.get();
}
