- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想生成这样的静态金字塔:
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 4 2 1
1 2 4 2 1
1 2 1
1
使用 PHP,我已经创建了这段代码:
<center>
<?php
$x1 = 1; $x2 = 128;
$str_tmp = "";
$cek = 0;
$start = 0;
for($i=0;$i<=7;$i++){
for($j=$i;$j<=13;$j++){
for($z=$i;$z<$i;$z++){
$str_tmp.= (" ") ;
}
if($x2==1){
$str_tmp.= $x2;
break;
}
if($cek==0){
$str_tmp.= $x1 . " ";
$x1 = $x1 * 2;
if($x1==$x2){
$cek = 1;
$x2 = $x2/2;
}
}if($cek==1){
$str_tmp.= $x1 . " ";
$x1 = $x1 /2;
}if($cek==1&&$x1<1){
break;
}
}
echo $str_tmp."</br>";
$str_tmp = "";
$x1 = 1;
$cek = 0;
}
?>
</center>
我觉得它看起来太复杂了。你们有更好的解决方案吗?我不介意你们用另一种语言编写代码。
谢谢
最佳答案
是这样的吗?
echo "<div style=\"text-align: center;\">";
for ($l=7; $l>=0; $l--){
$str = "";
for ($p=-$l; $p<=$l; $p++)
$str .= (1 << ($l - abs($p))) . " ";
echo substr($str,0,-1) . ($l ? "<br>" : "");
}
echo "</div>";
关于algorithm - 金字塔数算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29536203/
我想简化/减少我的代码,所以我尝试将具有重复参数的类的初始化放在它们自己的扩展类中。这是一个基于 Pyramid & Cornice 的 REST API。 我如何初始化 pyramid.httpex
我正在尝试构建一个由 4 个 DIV 组成的金字塔。布局如下所示: ------ | #1 | ------ ---------------- | #2 | #3 | #
我是 3d 绘图的新手。我只想用 5 个点 build 一个金字塔,然后从中切出一个平面。我的问题是我不知道如何填充边。 points = np.array([[-1, -1, -1],
我需要创建金字塔 slider 。 正如您在我当前的实现中看到的那样,我需要有一个位于其余元素顶部的中心图像。它们形成金字塔结构。图像也被放置在彼此下面,这种效果打破了一切,因为我需要转换它们(中心图
我一直在玩我在这里找到的演示:http://codepen.io/singhiskng/pen/dqiGj 我正在尝试制作一个 4 边形金字塔。
在jsp中实现如图所示的金字塔, 代码如下: 大致思路如下: 1、先画出前5行。因为 i+空格数=总行数,所以第一行的空格数是 总行数-i(第几行),然后画出 *,*的数目=2*i-11;
我在尝试找出一种使用用户输入创建金字塔的方法时遇到了很大的麻烦。它应该是这样的。 Enter a number between 1 and 9: 4 O O O O OOOO OOOO OOOO OO
我一直在寻找解决厄运金字塔的办法。到目前为止,我得出的结论如下: router.use('/create', function(res,req,next) { try { v
我刚刚开始处理。因此,我想创建一个函数,允许任何用户输入边数来创建 3D 金字塔。我正在使用处理 3。我需要一些帮助。提前致谢。我编写了一段目前有效的代码,但我想概括它。任何建议/提示将不胜感激。提前
我使用 JavaScript 创建了一个金字塔以下是我迄今为止使用 for 循环尝试的代码: function showPyramid() { var rows = 5; var ou
我被告知数据库超时(连接、交互、等待)设置为 30 秒。该数据库上有一个网站,人们往往会闲置超过 30 秒。 使用sqlalchemy,我需要在继续查询之前检查mysql连接是否仍然有效,否则站点会出
另一个棘手的问题。你在这里看到的是我的物理金字塔,它由 3 个 LED 构成,在 1 个平面上形成一个三角形,另一个 LED 在中间中心,比其他 3 个高约 18 毫米。第 4 个使三角形成为金字塔。
目标: 我正在尝试生成类似于下面给出的格式的金字塔。这需要一个基本的 Java 程序来接受用户输入、将数字转换为字符串、使用嵌套循环并生成格式化输出。下面是使用 8 行的所需输出示例。 Enter t
我的数据是多维组合数据(所有维度总和为 1 或 100)。我已经学会了如何使用三个变量来创建二维三元图。 我想添加第四个维度,使我的情节看起来像这样。 我愿意使用 python 或 R。我现在正在使用
我的数据是多维组合数据(所有维度总和为 1 或 100)。我已经学会了如何使用三个变量来创建二维三元图。 我想添加第四个维度,使我的情节看起来像这样。 我愿意使用 python 或 R。我现在正在使用
我是一名优秀的程序员,十分优秀!