473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

help in comparing

Hi,

I'm working a long code, part of which is as follows.

I get 2 numbers from 2 different field. Now I want to compare the 2
mumbers and see if atleast one of the digits are matching. for example:
A=123 and B=435. And I want to check if atleast one of the digit is
matching. In this case 3.

Can some one help me with this?

Thank You.

Siva.

Jan 8 '06 #1
8 1512
Siva wrote:
Hi,

I'm working a long code, part of which is as follows.

I get 2 numbers from 2 different field. Now I want to compare the 2
mumbers and see if atleast one of the digits are matching. for example:
A=123 and B=435. And I want to check if atleast one of the digit is
matching. In this case 3.

Can some one help me with this?

Thank You.

Siva.


Read in the two numbers in as strings. Scan through the strings and
build a list of the digits represented. If any digits appears twice in
the list, you have a match.

Rennie deGraaf
Jan 8 '06 #2
"Siva" <sa**********@utep.edu> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,

I'm working a long code, part of which is as follows.

I get 2 numbers from 2 different field. Now I want to compare the 2
mumbers and see if atleast one of the digits are matching. for example:
A=123 and B=435. And I want to check if atleast one of the digit is
matching. In this case 3.

Can some one help me with this?

Thank You.

Siva.


Myself, I'd probably convert them to strings then just do comparisons.
Jan 8 '06 #3
"Siva" <sa**********@utep.edu> wrote:
I'm working a long code, part of which is as follows.
I get 2 numbers from 2 different field. Now I want to compare the 2
mumbers and see if atleast one of the digits are matching. for example:
A=123 and B=435. And I want to check if atleast one of the digit is
matching. In this case 3.


What exactly do you mean by "compare" and "match"?
In your example, you say that the digit '3' "matches"
between the strings "123" and "435". And yet, it doesn't
"match" in a place-value sense. Do you mean in a "set"
sense? That is, "is the intersection of the sets {1,2,3}
and {3,4,5} non-empty?"? If so, look-up information on
std::set. You could put all the digits of one number-string
in a std::set, then iterate through the digits of a second
number-string and ask, for each digit, if it matches any
element of the set.

But I'm just guessing at your intentions. If you clarified
what you mean by "compare" and "match", perhaps I could help
more.

--
Robbie Hatley
Tustin, CA, USA
email: lonewolfintj at pacbell dot net
web: home dot pacbell dot net slant earnur slant
Jan 8 '06 #4
"Robbie Hatley" writes:
"Siva" <sa**********@utep.edu> wrote:
I'm working a long code, part of which is as follows.
I get 2 numbers from 2 different field. Now I want to compare the 2
mumbers and see if atleast one of the digits are matching. for example:
A=123 and B=435. And I want to check if atleast one of the digit is
matching. In this case 3.


What exactly do you mean by "compare" and "match"?
In your example, you say that the digit '3' "matches"
between the strings "123" and "435". And yet, it doesn't
"match" in a place-value sense. Do you mean in a "set"
sense? That is, "is the intersection of the sets {1,2,3}
and {3,4,5} non-empty?"? If so, look-up information on
std::set. You could put all the digits of one number-string
in a std::set, then iterate through the digits of a second
number-string and ask, for each digit, if it matches any
element of the set.

But I'm just guessing at your intentions. If you clarified
what you mean by "compare" and "match", perhaps I could help
more.

--
Robbie Hatley
Tustin, CA, USA
email: lonewolfintj at pacbell dot net
web: home dot pacbell dot net slant earnur slant


Well, Robbie, what part of his example didn't you understand? But I'm just
guessing at your problem. Perhaps if you clarified where your problem
originates, I could help you more.
Jan 8 '06 #5
Convert both the numbers in to string using itoa() function and then
compare each character of first string with each character of second.

cheers,

Jan 9 '06 #6
bak

Siva wrote:
Hi,

I'm working a long code, part of which is as follows.

I get 2 numbers from 2 different field. Now I want to compare the 2
mumbers and see if atleast one of the digits are matching. for example:
A=123 and B=435. And I want to check if atleast one of the digit is
matching. In this case 3.

Can some one help me with this?

Thank You.

Siva.


Jan 9 '06 #7
Thank you guys. I wanted to compare the digits in 2 numbers in my
example 123 and 435, and to see if atleast one digit matches. I joined
the 2 numbers and looked for repetition.

Thank You again.

Siva

Jan 9 '06 #8
"Siva" writes:
Thank you guys. I wanted to compare the digits in 2 numbers in my
example 123 and 435, and to see if atleast one digit matches. I joined
the 2 numbers and looked for repetition.


If "join" means concatenate, I don't like it. If you "join" 1223 and 579
you don't want a match.
Jan 9 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stephen | last post by:
I have to write a .Net application which can compare SQL Databases including things like: - DB structure, PK's, FK's, indexes and types of indexes i.e. should be able to detect if the same index...
4
by: Danny | last post by:
I set this up so the users can select more than one record so they can update records a bunch at a time. only one field is modified. How can I edit this table easily instead of scrolling through...
4
by: Abdessamad Belangour | last post by:
Hi all, I have an ArrayList ( phoneBook ) of structures (PhoneEntry's) holding the name and the owned phone numbers of a person as in below :...
2
by: test account | last post by:
I have an interface called IStatus. I have 2 classes, PurchaseOrder and Invoice. They each have an accessor named Status that return an object of type IStatus. I have 4 classes that implement...
1
by: Stephen | last post by:
I am trying to compare the tables in two similar databases using the SQLDMO object. I am able to use this object to access different SQL servers and choose two different databases. The versions of...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
9
by: isaac2004 | last post by:
hi i have a page that inclued a SQL statement that takes a user input from a form and displays the request from the database. every time i try to open the page i get an error message that says Data...
20
by: Bill Pursell | last post by:
This question involves code relying on mmap, and thus is not maximally portable. Undoubtedly, many will complain that my question is not topical... I have two pointers, the first of which is...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
9
by: teejayem | last post by:
I am looking for some help! I am currently developing a new game for an online community. The game is called Pokino which ishalf bingo and half poker. Wierd eh?! Anyway... The final part...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.