How do I make a smaller range with two given integers? [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
For example,
I have a range 14269-14274.
To conserve space on the screen my users want to have it display in the format 14269-74.
Another example would be a range of 14269-14529 which should output as 14269-529.
How would I achieve this?

Something like this should do the trick:
int a = 14269;
int b = 14529;
int endrange = b % pow(10, floor(log10(b - a) + 1));
You need to make sure that a < b though.

You can check the first digit that differs, output the first number and then the second one, starting at the first different digit.
This of course only makes sense if the two numbers have the same length.
Were you expecting the implementation?

Related

Regular expression in asp.net, containing either two fixed alphabets(D and DQ) or any two numbers [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to validate a text box (with max length 2) to contain only these 3 set of values.
(i) 00-99
(ii) Q
(iii) DQ
Invalid values are 1Q, 2D, QD, QQ, DD,etc etc
Alright you can use the following it will check for what you asked for its very simple and primitive regix but will work:
\d{2}|DQ|Q
If you want to better understand regular expressions the following might help:
http://msdn.microsoft.com/en-us/library/az24scfc.aspx
You can also use:
http://myregextester.com/index.php
As a tool to test your regix.
Hope that helps

Execution Control In C [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I was solving a problem where i was asked to output the list of numbers satisfying certain conditions. The score awarded depended upon the size of the output ( as it is a partial marking question). How do i restrict my code to keep outputting the numbers till it does hits the time limit.
It seems like the obvious structure would be something like this:
while (current_time < end_time) {
current_number = *next_number++;
if (meets_conditions(current_number))
output(current_number);
}

Palindrome without using extra space [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I know various ways to check if an integer is a palindrome or not by using string conversion, stack and number breaking, but here question is
"How can we check wether an integer is a palindrome or not, without using any extra space?"
You can revert a number with some code like:
int revert(int num) {
int reverted = 0;
while (num) {
reverted = reverted*10 + num%10;
num /= 10;
}
return reverted;
}
And now you only check if
num == revert(num)
That is all. Sorry for giving the exact solution instead of just a tip, but I don't think I could have given any tip without the solution itself.

Generate all Binary Combinations C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to write a program that you give an input (number of digits n) and you get as an output a vector of all possible binary grey code generated.
For example,
if n=2, results should be:
V= {00, 01, 10,11}
Actually I am interested in having them bit by bit and not whole integer. Meaning I want to have a 2 D array of integers where I have each word in rows and bits (as int) in cols
Hint: Gray code of num is (num>>1) ^ num. Go through all numbers of the 0..2^N-1 range, and compute their Gray code representation using this simple formula.
EDIT Another hint: the simplest way to convert an integer to binary is using bitset:
bitset<N>((num>>1) ^ num).to_string()
The set V equals { 0, ..., 2^n-1 }. Just compute this set.

All valid words that must have even number of a's or even number of b's [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
All valid words that must have even number of a's or even number of b's
I would recommend this site: http://rubular.com/. Its a sandbox for Regular Expressions where you can play around with them. It should help you solve your problem.
You cannot do this with one regular expression. For one word you'd need to do something like
if ((replace(/[^Aa]/g, "").length & 1) == 0)
Of course this highly depends on your programming language (the above would work in JavaScript)