Removal of the garlic guest element

Source: Internet
Author: User

Element removal

Given an array and a number (the number is not necessarily in the array), delete the number from the array and return the remaining array length.

such as: a[] = {1, 2, 3, 4, 5}, to remove the number 3, the returned array length is 4.

Dear little Friends, is the topic very simple?

Hint: int removeelement (int a[], int n, int elem)

where n represents the length of the array, and Elem represents the element to be deleted.

Format:

Enter a number n, enter an array a[n], and then enter the element elem to delete, returning the remaining array length index.

1#include"iostream"2 #defineMAX 100003 using namespacestd;4 intMain ()5 {6     intN, A[max], elem, ans;7CIN >>N;8      for(inti =0; i<n; i++)9scanf"%d", &a[i]);Ten  OneCIN >>Elem; AAns =N; -  -      for(inti =0; i<n; i++) the     { -         if(A[i] = =elem) -         { -ans--; +         } -     } +  Acout <<ans; at  -}

Removal of the garlic guest element

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.