82 449
Assignments Done
100%
Successfully Done
In January 2020

Answer to Question #13584 in C++ for prakash

Question #13584
Adjacent repetitions - have a number 13368945501113. In this number there are some adjacent repetitions. Wherever we see a number being repeated side by side, we need to add them. So the number would look like 16689410033 after the first iteration. now we see that this resulting number has repetitions too. So we need to do the same operation until there are no more adjacent repetitions. The final output of this should be 4894106. The program should accept any number like the above, and should return it after removing all the adjacent duplicates.
1
2012-08-30T09:39:34-0400
#include <iostream>
using namespace std;
#include <vector>

int main ()
{
int num;
cin>>num;

system("pause");
return 0;
}
{
long long result = 0;
vector<long long> operationWithIt;
while(number>0){
& long long numberUsingNow;
& numberUsingNow = number%10;
& operationWithIt.push_back(numberUsingNow);

& number -= operationWithIt[operationWithIt.size() - 1];
& number /= 10;
}
int check = 1;
while (check > 0){

& check = 0;
& for (int i = operationWithIt.size() - 1 ; i > 0 ; i--){
& int k;
& if (operationWithIt[i] == operationWithIt[i-1]){
& k = i + 1;
& check++;
& add += operationWithIt[i] + operationWithIt[i-1];
& i--;
& while (i > 0 && (operationWithIt[i] == operationWithIt[i-1]) ){
& i--;
& }
& } else {
& operationWithIt.erase(operationWithIt.begin() + i + 1, operationWithIt.begin() + k);
& }
& }
& }
}

for (int i = operationWithIt.size() - 1 ; i >= 0 ; i--)
{
& result += operationWithIt[i];
& result *= 10;
}
result /= 10;
return result;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!