how to eliminate number

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 51
Reputation: shamila08 is an unknown quantity at this point 
Solved Threads: 0
shamila08 shamila08 is offline Offline
Junior Poster in Training

how to eliminate number

 
0
  #1
Aug 27th, 2008
Hi all....

i have problem with number:
example:
1234 is equivalent to 1432 ( based on maths concept), then erase/delete 1432
2143 is equivalent to 2341, then erase/ delete 2341, and so on

How to program it in C++
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: littlestone is an unknown quantity at this point 
Solved Threads: 6
littlestone littlestone is offline Offline
Light Poster

Re: how to eliminate number

 
0
  #2
Aug 27th, 2008
Which container do you use to store the number? vector? list?
if you use list, you can use the unique(op) function to eliminate the duplicate number. the op is a function or a functional object used to predicate whether two number is equivalent.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 51
Reputation: shamila08 is an unknown quantity at this point 
Solved Threads: 0
shamila08 shamila08 is offline Offline
Junior Poster in Training

Re: how to eliminate number

 
0
  #3
Aug 27th, 2008
Originally Posted by littlestone View Post
Which container do you use to store the number? vector? list?
if you use list, you can use the unique(op) function to eliminate the duplicate number. the op is a function or a functional object used to predicate whether two number is equivalent.
thanks. here example on what i use.
  1. void equiv(int *x, int start, int n)
  2. {
  3. write(x, n);
  4. if (start < n) {
  5. int i, j;
  6. for (i = n-2; i > start; i--) {
  7. for (j = i + 1; j <n; ++j) {
  8. shift(x, i, j);
  9. equiv(x, i, n);
  10. }
  11. shiftleft(x, i, n);
  12. } }}
sorry i 'm not familiar about op function. could you give some example based on my code here?
the output is same as before.
Last edited by Ancient Dragon; Aug 27th, 2008 at 10:03 am. Reason: correct code tags -- spaces not allowed between brackets
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: littlestone is an unknown quantity at this point 
Solved Threads: 6
littlestone littlestone is offline Offline
Light Poster

Re: how to eliminate number

 
0
  #4
Aug 27th, 2008
I did not understand your algorithm for predicate whether two number are equivalent.
I think at least the equivalent function should return a bool value.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 18
Reputation: l4z3r is an unknown quantity at this point 
Solved Threads: 0
l4z3r l4z3r is offline Offline
Newbie Poster

Re: how to eliminate number

 
0
  #5
Aug 27th, 2008
i'm sort of getting the idea, shamila. If you would post the shift() function, i think I might be able to help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: how to eliminate number

 
0
  #6
Aug 27th, 2008
You aren't talking about sofic shifts, are you? If so, how are you representing your graphs?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 51
Reputation: shamila08 is an unknown quantity at this point 
Solved Threads: 0
shamila08 shamila08 is offline Offline
Junior Poster in Training

Re: how to eliminate number

 
0
  #7
Aug 27th, 2008
Originally Posted by l4z3r View Post
i'm sort of getting the idea, shamila. If you would post the shift() function, i think I might be able to help.
to I4Z3r: here my shift function
[code=cplusplus]
void shift(int *x, int i, int j)
{
int t;
t = x[i];
x[i] = x[j];
x[j] = t;
}
[code]
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 51
Reputation: shamila08 is an unknown quantity at this point 
Solved Threads: 0
shamila08 shamila08 is offline Offline
Junior Poster in Training

Re: how to eliminate number

 
0
  #8
Aug 27th, 2008
Originally Posted by Duoas View Post
You aren't talking about sofic shifts, are you? If so, how are you representing your graphs?
yes, it's refer to how array the number. not a complicated one. example from my output as follows :
1234
1243
1423
1432.
but i dont want all this four because there is equivalent among them.
for example 1234 ==1432. i have to delete 1432.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC