Advertisement
Guest User

gabi

a guest
Jan 20th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. char * deleteAndReturnRepeatiing(char *, unsigned);
  5. int main() {
  6.     cout << "Enter your big number - between 20 and 50 nums: ";
  7.  
  8.     char * bigNum = new char [50];
  9.     cin >> bigNum;
  10.     deleteAndReturnRepeatiing(bigNum, 50);
  11.    
  12.     if (bigNum != nullptr)
  13.     {
  14.         delete[] bigNum;
  15.         bigNum = nullptr;
  16.     }
  17. }
  18.  
  19. char * deleteAndReturnRepeatiing(char * bigNum, unsigned size)
  20. {
  21.     char * repeatingNums = new char[size];
  22.     int count = 0;
  23.     for (int i = 0; i < size; i++)
  24.     {
  25.         for (int k = 1; k < size; k++)
  26.         {
  27.             if (bigNum[i] == bigNum[k])
  28.             {
  29.                 repeatingNums[count] = bigNum[i];
  30.                 count++;
  31.                 for (; k < size - 1; k++)
  32.                 {
  33.                     // Assign the next element to current location.            
  34.                     bigNum[k] = bigNum[k + 1];
  35.                 }
  36.  
  37.                 // Remove the last element as it has been moved to previous index.
  38.                 bigNum[size - 1] = 0;
  39.                 size = size - 1;
  40.             }
  41.         }
  42.     }
  43.     cout << "The repeating nums are: " << endl;
  44.     for (size_t i = 0; i < count; i++)
  45.     {
  46.         if (repeatingNums[i] >= 48 && repeatingNums[i] <= 57)
  47.         {
  48.             cout << repeatingNums[i] << " ";
  49.  
  50.         }
  51.     }
  52.     cout << endl;
  53.    
  54.     cout << "The new big num without the repeating ones: " << endl;
  55.     for (size_t k = 0; k < size; k++)
  56.     {
  57.         if (bigNum[k] >= 48 && bigNum[k] <= 57)
  58.         {
  59.             cout << bigNum[k] << " ";
  60.         }
  61.     }
  62.     cout << endl;
  63.     return repeatingNums;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement