for example I have a c++ which takes 2 integers from a file. For example int a = 2052342 and int b = 2. I need to do a search that will search if b is inside a. So in this example, b is inside a, but if b would be for example 7 it wouldn’t be. What kind of function, should I use, and could you give me a quick demo of it?
Edit: No it’s not a homework, I will compete in Programmers Olympiad this year, so I’m programming all of the C++ exercises that were in last Programmers Olympiads.
for example I have a c++ which takes 2 integers from a file. For
Share
You use a pretty flakey example without much explanation of what “if b is inside a’ means. Are you just checking to see if the substring of ‘int b’ is inside ‘int a’? if B were 205, or 234, would that count?
Perhaps not the best way, but simple enough, is to convert each integer to a string, and then do a substring check to see if stringB is a substring of stringA.
Update: Infact, when you’re parsing your file, i’d just read them in as string, don’t even look at this as a problem of integers. You’re just doing substring checks. Also, if you parse them as integers, you’d run in to 0-padding being lost.
If you’re talking about division or something else, that could be done by doing division.