Saturday, 30 January 2016

Delete Duplicate Elements in Array For Positive Value Problem Solution Using C++.



Solution:

#include <iostream>
#include<cstring>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
 int max = -999999,result[1000],ar[] = {8,9,1,11,2,5,4,7,8,9,2,3,1,4,7,5,2,3,6,9,0,4,5,1,1,4,0,10};
 int n = sizeof(ar)/sizeof(int);
 memset(result,-1,sizeof(ar));
 
 for(int i = 0; i < n; i++){
  result[ar[i]]++;
  if(max < ar[i])max = ar[i];
 }
 for(int i = 0; i <= max; i++)if(result[i]!=-1)cout << i << " ";
 cout << endl;
 return 0;
}

No comments:

Post a Comment