I
I
igoodmood2015-10-18 12:14:22
Algorithms
igoodmood, 2015-10-18 12:14:22

How to correctly specify the interval of numbers at which the case of the word will be correctly selected?

How to specify the correct interval so as not to list numbers from 1 to 100. For example, when entering the number "67", the third case option was selected.
c84a1d68ecf948f9ab1ebb57621ff23e.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Ravenenok, 2015-10-18
@Ravenenok

x = (остаток от деления N на 10)
Если  x == 1 и N != 11 {
  "Ворона"
  Иначе Если x >= 2 и x <= 4 и N < 12 и N > 14 {
    "Вороны"
    Иначе {
      "Ворон"
    }
  }  
}

M
Mercury13, 2015-10-18
@Mercury13

Here are the plural rules for different languages.
www.unicode.org/cldr/charts/latest/supplemental/la...
I worked with something similar, and if it is possible to issue the same answer in two different branches, then so be it.
The remainder of division by 100 from 5 to 20 → "raven"
The remainder of division by 10 is 1 → "crow"
The remainder of division by 10 from 2 to 4 → "ravens"
Otherwise - "raven".
I wrote down these rules in this form.

<pluralRules nDecisions="3" unknownInt="2">    ← вариантов три; если ни одно из правил не подошло, брать последний («ворон»)
    <rule mod="100" min="10" max="20" decide="2" />  ← остаток на 100 от 10 до 20 — «ворон»
    <rule mod="10" min="1" max="1" decide="0" />
    <rule mod="10" min="2" max="4" decide="1" />
  </pluralRules>

A
abcd0x00, 2015-10-19
@abcd0x00

How to specify the correct interval so as not to list numbers from 1 to 100.

It is necessary to take only the last two digits (even if the number is three-digit) - 00..99.
Then you just divide them into two variables and do the check separately.
That is, there should be no analysis of two-digit numbers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question