How to get on input ONLY numeric characters on IJVM? - numeric

I'll do a "SIMPLE program" on IJVM, but it asks:
You must get on input ONLY numeric characters ( 0x30 to 0x39).
So if I'll insert for example (A or b or g etc.. ) it will stop with "HALT".
How can I make a condition that take the value from 0x30 to 0x39 without alphabetic characters?

You will need two separate tests.
First, test if the input is not less than 0x30.
Second, test that the input is less than 0x40.
If it meets both conditions, then it is input that you want.
Response to comment about three types of 'if':
Each conditional branch has two possible jump targets, one for when the condition is true, the other for when the condition is false.
For the n < 0 test, the TRUE address will be taken when n < 0, the FALSE address will be taken when n >= 0. The n < 0 test can also test for n >= 0, depending on the address taken.

Related

I don't understand the examples, input and output in codeforces's problems

You are given three integers n, a, and b. Determine if there exist two permutations p and q of length n, for which the following conditions hold:
The length of the longest common prefix of p and q is a.
The length of the longest common suffix of p and q is b.
A permutation of length n is an array containing each integer from 1 to n exactly once. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
Input
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of test cases follows.
The only line of each test case contains three integers n, a, and b (1≤a,b≤n≤100).
Output
For each test case, if such a pair of permutations exists, output "Yes"; otherwise, output "No". You can output each letter in any case (upper or lower).
Example
input
4
1 1 1
2 1 2
3 1 1
4 1 1
output
Yes
No
No
Yes
This is a random Codeforces' problem.
I don't understand the example, input and output.

Boundary Value Analysis, Why does use two values inside the boundary?

I can't understand why to use two values inside the boundary when using Boundary Value Analysis.
For instance, the program has the requirement: 1) Values between 1 and 100 are true, otherwise false.
func calc(x):
if (x >= 1 and x <= 100):
return True
else:
return False
A lot of books (Pressman, for instance) say you have to use the inputs 0, 1, 2, 99, 100 and 101 to test such program.
So, my question is: Why does use the inputs '2' and '99'?
I try to make a program with a fault that the test case set (0, 1, 2, 99, 100 and 101) expose a fail and the test case set (0, 1, 100, 101) does not expose it.
I can't make such program.
Could you make such program?
If not, it is a waste of resource create redundant test cases '2' and '99'.
The basic requirement is to have +-1 of the boundary values. So to test values for a range of 1-100
One test case for exact boundary values of input domains each means
1 and 100.
One test case for just below boundary value of input domains each
means 0 and 99.
One test case for just above boundary values of input domains each
means 2 and 101.
To answer your question - Why does use the inputs '2' and '99'? It is because if you are following BVA, you are checking both the limits (upper as well as lower) of the range to ensure that the software is behaving correctly. However, there are no hard and fast rules. If the range is big enough, then you should have more test points. You can also test the middle values as part of BVA.
Also, you can use Switch Case statements to create a program or multiple Ifs.

how we can find regular expression for following strings

Find regular expressions representing the following set:
The set of all strings over {a,b} in which the number of
occurrences of a is divided by 3.
The set of all strings over {0,1} beginning with 00
You can draw out a DFA and use that to find the regular expression.
For example, for 1., it would be
Then you use convert this into a regular expression. This is one way
For 1, you need an expression that gives every possible way of having a string over {a,b} with the occurrences of a divisible by 3. There can be 0 a's since 0 is divisible by 3. There can be 3 a's, 6 a's, 9 a's, and so on. An expression for this is (bababab)+b. The second term allows for the possibility of 0 a's and any amount of b's since 0 a's is divisible by 3. The first term accounts for all other possibilities of strings with a number of a's divisible by 3.
For 2, the set of all strings over {0,1} is (0+1)* and if it must begin with 00, then the regex is simply 00(0+1)*

what is the best data model to represent mathematical range (in database,xml,json...)?

mathematical range,for example:
greater or equal to 50 and smaller than 100 (>=50 && < 100)
smaller than 10 or greater than 40 (<10 || >40)
I have been thinking about how to represent mathematical range in a file and database, the range may be input by non programmer and I need to keep the input simple,but at another side, it also need to keep the input easy to convert to data and easy to check error input e.g.:"<10 || >100" seems the most simple but it is harder for me to parse the string to get the data,also need to consider input format error
I have been considering some input methods,using >=50 && < 100 as example,which is in key value form:
1.using 1 string to represent whole range:
<rangeInString>=50 && < 100</rangeInString>
2.separate 2 strings,one represent lower bound and another one represent upper bound,then parse each string in program:
<lowerBound> >=50 </lowerBound>
<upperBound> <100 </upperBound>
3.separate lower and upper bound,also separate the sign from number:
<lowerBound>
<sign> >= </sign>
<data>50</data>
</lowerBound>
<upperBound>
<sign> < </sign>
<data>100</data>
</upperBound>
4.separate lower bound and upper bound,also separate sign, and also separate the case that if includes the equal condition:
<lowerBound>
<sign> > </sign>
<isIncludeEqual>true</isIncludeEqual>
<data>50</data>
</lowerBound>
<upperBound>
<sign> < </sign>
<isIncludeEqual>false</isIncludeEqual>
<data>100</data>
</upperBound>
5.auto detect using "&&" or "||",e.g.:>= A with < B,if A < B,must be "&&" e.g.(>= 50 && <100),otherwise it is "||" e.g.(>= 100 || <50):
<A>
<sign> > </sign>
<isIncludeEqual>true</isIncludeEqual>
<data>50</data>
</A>
<B>
<sign> < </sign>
<isIncludeEqual>false</isIncludeEqual>
<data>100</data>
</B>
6.use a field "isAnd" to separate >=50 && < 100 (true) and <=50 || > 100 (false)instead of using field sign "<" and ">" :
<lowerBound>
<isIncludeEqual>true</isIncludeEqual>
<data>50</data>
</lowerBound>
<upperBound>
<isIncludeEqual>false</isIncludeEqual>
<data>100</data>
</upperBound>
<isAnd>true</isAnd>
7.other data model...
I need to consider somethings:
1.easy for non programmer to input
2.easy to convert or parse to data into program
3.easy to check error ,for example,parse string increase the complexity of converting data and checking incorrect format,also there may have other incorrect format,e.g.:<=50 && >100 should not be valid, I may allow auto detect using "&&" or "||" by the sign of input,but it may increase the complexity of the code
can anyone have idea?
Why "encode" it? There's no benefit or need and some hassle to use it.
Just store the exclusive range end values
low_end int,
high_end int,
You can then convert these raw values to useable expressions either in SQL or application code. You don't need to consider inclusive values because "n exclusive" === "n inclusive - 1" for low end and "n exclusive" === "n inclusive + 1" for high end.
Here's an SQL implementation:
where (low_end is null or col > low_end)
and (high_end is null or col < high_end)
If the range end values need to be floating point numbers, you'll need a little more:
low_end int,
low_inclusive boolean,
high_end int,
high_inclusive boolean,
And more code:
where (low_end is null or col > low_end + case when low_inclusive then 0 else 1 end)
and (high_end is null or col < high_end - case when high_inclusive then 0 else 1 end)
This is a good question, what about a combination of interval notation as suggested by Gordon and a given character for infinity. This combined with separate fields (or a parsing algorithm) could accomplish the task of defining any range.
For example, the range (3<x<20) could be written as (3,20). The range (x<=10 || x>30) could be written as the combination of
(-_,10],(30,_).
Where _ represents infinity. Or use the actual Infinity symbol character, ∞, Unicode U+221E.
This way would be pretty clear for those with a mathematics background, I believe, and would provide infinite flexibility.
I hope you find this helpful.
PostgreSQL does ranges natively.
The representation looks like this:
[low, high)
[ or ] = inclusive
( or ) = exclusive
Unbounded looks like this: [low-value, infinity]
http://www.postgresql.org/docs/9.4/static/rangetypes.html
Specifically addressing your options:
Why represent it in a format that you have to parse? A case could be made that you store it in a format that your code can parse, but what if you need to access it with a different programming language?
Same as 1.
Getting close, but you would need to subsume the bounds within a range object that includes && or ||. Also, no need for element, which is implied by "lower" and "upper" and could be replaced by an inclusive flag like you have in 4.
No need for
Unnecessary abstraction...it's just a range
That could work
Other data model:
The data is structured, so could work in json, xml, relational, or even as a set of semantic triples.

Create all combinations of a word through spaces in the Console Application

I'm trying to experiment with this, http://gyazo.com/8190a3c98a520bbeb77335e05ea5a636 (a visual basic console application). I want it to allow the user to enter in a word such, and have the console reply with it in all spaced combinations possible, so:
Say i'm using the word TEST, for example it would be created spaced out like this:
T EST
T E ST
T E S T
TE ST
TES T
T ES T
And so on... (Such as every combination it can be spaced out with multiple spaces or not)
Is this possible through the Console Application?
When counting, you start at the lowest digit. You start with that digit at zero and you count up until you reach the highest value for that digit, like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Then, once you reach the highest value, you have to add a second digit (e.g. 10). Then you go from lowest to highest again on the lowest digit again (e.g. 10 - 19) before incrementing the second digit again (e.g. 20). In that way, once you reach 999, you will have listed every possible combination of values in a three digit number.
When counting in binary, it works the same way, but the highest value for each digit is one, so you count up on the lowest digit like this: 0, 1. Then you have to add the second digit and count up again: 10, 11. Then you need to add a third digit (e.g. 100) and do it all again on the first two. By the time you get to 111, you will have listed every possibly combination of 1's and 0's in a three digit binary number.
So, if you think of the space between each letter as a digit in a binary number, where 0 means no space and 1 means there is a space, then all you have to do is count up from 0 to the highest value in a binary number that is the same number of digits as the length of your word, minus 1. So, for instance, with the word TEST, the the counting would look like this:
000 = TEST
001 = TES T
010 = TE ST
011 = TE S T
100 = T EST
...