943,853 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 693
  • C++ RSS
Aug 27th, 2008
0

how to eliminate number

Expand Post »
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++
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
shamila08 is offline Offline
51 posts
since Aug 2008
Aug 27th, 2008
0

Re: how to eliminate number

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.
Reputation Points: 14
Solved Threads: 6
Light Poster
littlestone is offline Offline
42 posts
since Mar 2008
Aug 27th, 2008
0

Re: how to eliminate number

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.
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
shamila08 is offline Offline
51 posts
since Aug 2008
Aug 27th, 2008
0

Re: how to eliminate number

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.
Reputation Points: 14
Solved Threads: 6
Light Poster
littlestone is offline Offline
42 posts
since Mar 2008
Aug 27th, 2008
0

Re: how to eliminate number

i'm sort of getting the idea, shamila. If you would post the shift() function, i think I might be able to help.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
l4z3r is offline Offline
18 posts
since Aug 2008
Aug 27th, 2008
0

Re: how to eliminate number

You aren't talking about sofic shifts, are you? If so, how are you representing your graphs?
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Aug 27th, 2008
0

Re: how to eliminate number

Click to Expand / Collapse  Quote originally posted by l4z3r ...
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]
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
shamila08 is offline Offline
51 posts
since Aug 2008
Aug 27th, 2008
0

Re: how to eliminate number

Click to Expand / Collapse  Quote originally posted by Duoas ...
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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
shamila08 is offline Offline
51 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Segmentation Fault
Next Thread in C++ Forum Timeline: trying to print my Queue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC