-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
QQ wrote:
Hello I have a integer range
[a1 a2]
Now I have another integer range [b1 b2]
ai,bi =0,1,....,M
I wanna compare the relationship between the two ranges
for example
[a1 a2]=[0 99]
[b1 b2]=[20 80]
so there are 9 situations
1) a1=b1, a2<b2
2) a1=b1, a2=b2
...
I'd like to know which situation it belongs to
My current algorithm is to set another array c[2]
if a1<b1 set c[0]=0
if a1=b1 set c[0]=1
if a1>b1 set c[0]=2
if a2<b2 set c[1]=0
if a2=b2 set c[1]=1
if a2>b2 set c[1]=2
decide the situation by c
Is there any better way for it?
A little trickery might do.
Transforming your non-C example above into C, here's a function that
would return the 'situation' number...
int situation(int a1, int a2, int b1, int b2)
{
int c1, c2;
c1 = (a1 < b1) ? 0 : ((a1 == b1) ? 1: 2);
c2 = (a2 < b2) ? 0 : ((a2 == b2) ? 1: 2);
return (c1 * 3) + c2;
}
which returns
0 when (a1 < b1) and (a2 < b2)
1 when (a1 < b1) and (a2 == b2)
2 when (a1 < b1) and (a2 > b2)
3 when (a1 == b1) and (a2 < b2)
4 when (a1 == b1) and (a2 == b2)
5 when (a1 == b1) and (a2 > b2)
6 when (a1 > b1) and (a2 < b2)
7 when (a1 > b1) and (a2 == b2)
8 when (a1 > b1) and (a2 > b2)
- --
Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFCpwzsagVFX4UWr64RAjzvAJ42pzpOh60YEKqDbZAmO6 6HdZxgiwCgxlNo
wkBTEpsQBrMPh6/aElCpYu8=
=yGOG
-----END PGP SIGNATURE-----