Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. int z1(int array_start[], int* array_end, unsigned int n) {
  2.     unsigned int index = n;
  3.     for(int i = 0; i < n; i++) {
  4.         for (int j = 0; j < n; j++) {
  5.             if ((array_start[i] + array_end[j])%10 == 0) {
  6.                 array_end[j] = 10;
  7.                 array_start[i] = 0;
  8.                 index--;
  9.                 break;
  10.             }
  11.         }
  12.     }
  13.    
  14.     int* tempArr = new int[n];
  15.     int diffInd = 0;
  16.    
  17.     for(int i = 0; i < n; i++) {
  18.         if (array_end[i] == 10) {
  19.             diffInd++;
  20.         }
  21.         else
  22.             (tempArr[i-diffInd] = array_end[i]);
  23.     }
  24.    
  25.     delete[] array_end;
  26.     array_end = new int[n-diffInd];
  27.    
  28.     for(int i = 0; i < n-diffInd; i++) {
  29.         array_end[i] = tempArr[i];
  30.     }
  31.     delete[] tempArr;
  32.     return index;
  33. }
  34.  
  35. int main() {
  36.     unsigned int n = 10;
  37.     int arr[10] = {1, 2, 3, 4, 5, 6, 7, 5, 3, 1};
  38.     int* arrAll = new int[10];
  39.    
  40.     for(int i = 0; i < n; i++) {
  41.         arrAll[i] = (i+1)%10;
  42.     }
  43.    
  44.     std::cout << z1(arr, arrAll, n) << std::endl;
  45.    
  46.     for(int i = 0; i < z1(arr, arrAll, n); i++) {
  47.         std::cout << arrAll[i] << " ";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement