O
O
Olya Pilipenko2014-03-27 11:08:55
PHP
Olya Pilipenko, 2014-03-27 11:08:55

How to solve this problem purely by PL methods?

Two positive integers A and B are given. It is necessary to print the word "YES" or "NO" in accordance with whether it is possible to obtain a decimal representation of the number A by crossing out one or more digits of the number B.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Guketlev, 2014-03-27
@Yavanosta

otvet.mail.ru/edu_homework
But in general:
1. Bring both numbers to the line.
2. Remember the position in the number A = 1
3. Remember the position in the number B = 1
4. Take the current digit of the number A
5. Compare with the current digit of the number B
6. Increase the position in the number B
8. If the numbers are not equal, go to step 5
7. If the digits are equal, increase the position in the number A and go to step 4
9. If the number A runs out first - print YES
10. If the number B runs out first - print NO

D
Denis Pushkarev, 2014-03-27
@rock

var num = 123
  , d   = '\\d*'
  , reg = RegExp(d + num.toString().split('').join(d) + d);

console.log(reg.test(123));       // => true
console.log(reg.test(210025535)); // => true
console.log(reg.test(12));        // => false
console.log(reg.test(1032554));   // => false

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question