Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- char * deleteAndReturnRepeatiing(char *, unsigned);
- int main() {
- cout << "Enter your big number - between 20 and 50 nums: ";
- char * bigNum = new char [50];
- cin >> bigNum;
- deleteAndReturnRepeatiing(bigNum, 50);
- if (bigNum != nullptr)
- {
- delete[] bigNum;
- bigNum = nullptr;
- }
- }
- char * deleteAndReturnRepeatiing(char * bigNum, unsigned size)
- {
- char * repeatingNums = new char[size];
- int count = 0;
- for (int i = 0; i < size; i++)
- {
- for (int k = 1; k < size; k++)
- {
- if (bigNum[i] == bigNum[k])
- {
- repeatingNums[count] = bigNum[i];
- count++;
- for (; k < size - 1; k++)
- {
- // Assign the next element to current location.
- bigNum[k] = bigNum[k + 1];
- }
- // Remove the last element as it has been moved to previous index.
- bigNum[size - 1] = 0;
- size = size - 1;
- }
- }
- }
- cout << "The repeating nums are: " << endl;
- for (size_t i = 0; i < count; i++)
- {
- if (repeatingNums[i] >= 48 && repeatingNums[i] <= 57)
- {
- cout << repeatingNums[i] << " ";
- }
- }
- cout << endl;
- cout << "The new big num without the repeating ones: " << endl;
- for (size_t k = 0; k < size; k++)
- {
- if (bigNum[k] >= 48 && bigNum[k] <= 57)
- {
- cout << bigNum[k] << " ";
- }
- }
- cout << endl;
- return repeatingNums;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement