你怎么找到答案? [英] How do you find the answer?

查看:60
本文介绍了你怎么找到答案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Raj解决了以下难题:

24 - > 1

1264 - > 2

9899 - > 5

349 - > x

Raj确定可以通过计算数字中数字的孔数来解决这个难题。例如1,2,3,5,7没有洞,0,4,6,

9每个有1个洞,8个有2个洞。因此,2是x到最后一行的值。

由于这一发现,Raj现在想要使用计算机程序来解决这个难题。您必须编写一个签名为

solvePuzzle(int num)的函数,其中num是输入整数,返回值是num中的孔数。

约束:

1≤num≤10

没有前导零。

示例输入#0:

630

样本输出#0:

2

解释#0:

6和0各有一个洞

样本输入#01:

1288

样本输出#01:

4

说明#01:

两个8都包含2个孔。



我尝试过:



echo rand()。 \ n;

echo rand()。 \ n;



echo rand(5,15);

?>

Raj has solved the puzzle below:
24 -> 1
1264 -> 2
9899 -> 5
349 -> x
Raj determined that the puzzle can be solved by counting the number of holes in the digits of a number. e.g. 1,2,3,5,7 have no holes, 0, 4, 6,
9 have 1 hole each, and 8 has 2 holes. 2 is therefore the value of x to the last line.
Excited by this discovery, Raj now wants to solve this puzzle using a computer program. You have to write a function whose signature is
solvePuzzle(int num) where num is the input integer, and the return value is the number of holes in num.
Constraints:
1 ≤ num ≤ 10
There will be no leading zeroes.
Sample Input #0:
630
Sample Output #0:
2
Explanation #0:
6 and 0 have one hole each
Sample Input #01:
1288
Sample Output #01:
4
Explanation #01:
Both 8's contain 2 holes each.

What I have tried:

echo rand() . "\n";
echo rand() . "\n";

echo rand(5, 15);
?>

推荐答案

你需要的只是一些逻辑思维。如果想一想,你应该得出结论,操作系统中没有存储数字字形孔数的预定义信息。这是你应该在你的代码中定义的唯一数据。



一切都减少到有一个代表孔数的数组。很明显,数组的索引集应该代表数字,所以它应该是索引0到9的数组。从这里,你可以得到孔的总和,以及关于的解释遇到的每个数字。这确实是小学的问题。开始工作。



-SA
All you need is some logical thinking. If think a bit, you should come to conclusion that there is no predefined information stored in the OS on the number of holes in digits' glyphs. This is the only piece of data you should define in your code.

Everything is reduced to having an array of numbers representing the number of holes. The set of indices of the array, quite obviously, should represent the digits, so it should be an array on the set of indices 0 to 9. From here, you can derive the sum of holes, as well as the "explanation" on each digit encountered. This is really the problem for elementary school. Start working.

—SA


这篇关于你怎么找到答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆