Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int z1(int array_start[], int* array_end, unsigned int n) {
- unsigned int index = n;
- for(int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if ((array_start[i] + array_end[j])%10 == 0) {
- array_end[j] = 10;
- array_start[i] = 0;
- index--;
- break;
- }
- }
- }
- int* tempArr = new int[n];
- int diffInd = 0;
- for(int i = 0; i < n; i++) {
- if (array_end[i] == 10) {
- diffInd++;
- }
- else
- (tempArr[i-diffInd] = array_end[i]);
- }
- delete[] array_end;
- array_end = new int[n-diffInd];
- for(int i = 0; i < n-diffInd; i++) {
- array_end[i] = tempArr[i];
- }
- delete[] tempArr;
- return index;
- }
- int main() {
- unsigned int n = 10;
- int arr[10] = {1, 2, 3, 4, 5, 6, 7, 5, 3, 1};
- int* arrAll = new int[10];
- for(int i = 0; i < n; i++) {
- arrAll[i] = (i+1)%10;
- }
- std::cout << z1(arr, arrAll, n) << std::endl;
- for(int i = 0; i < z1(arr, arrAll, n); i++) {
- std::cout << arrAll[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement