用伪代码迭代 M x N 矩阵?

发布于 2024-11-26 17:48:53 字数 489 浏览 1 评论 0原文

好吧,由于一些错误,我无法发布代码,所以我将对你们进行伪代码。请用代码和数学来回答。我的数学很糟糕,试图通过代码计算出数学对我来说是一项不可能完成的任务。

我的伪代码仅使用数字和字母,这将形成一个 2x2 矩阵,但我希望能够以这种方式迭代 m × n 矩阵。我只是认为从特定(无变量)到一般(包含变量)更容易。

Letter a, letter b; number 1, number 2 ==>

Letter a id=1, letter b id=1 | 
number 1 id=1, number 2 id=2 |
Letter_by_Number 1by1, Letter_by_Number 1by2, Letter_by_Number 2by1, Letter_by_Number 2by2

谁能告诉我如何在 C++、Python、PHP 的 SimpleXML 或 XSL 中执行此操作?如果我能用这些语言中的任何一种来记下数学,我想我就能弄清楚其他一切。

Well, I can't post code because of some bug, so I'm going to pseudocode you guys. Please, respond with code and math. I am terrible at math, and trying to figure math out via code is an impossible task for me.

My psuedocode uses only numbers and letters, which will form a 2x2 matrix, but I want to be able to iterate across m by n matrices in this fashion. I just think that it's easier to go from specific (no variables) to general (variable-inclusive).

Letter a, letter b; number 1, number 2 ==>

Letter a id=1, letter b id=1 | 
number 1 id=1, number 2 id=2 |
Letter_by_Number 1by1, Letter_by_Number 1by2, Letter_by_Number 2by1, Letter_by_Number 2by2

Can anyone tell me how to do this in C++, Python, PHP's SimpleXML, or XSL? If I can get the math down in any of these languages, I think I can figure everything else out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑,眼淚并存 2024-12-03 17:48:53

像这样的东西吗?

$m = 2; 
$n = 2; 

for($i = 1; $i <= $m; $i++) {
    for($j = 1; $j <= $n; $j++) {
         echo $i." x ".$j."\n"; 
    }
}

结果:

1 x 1
1 x 2
2 x 1
2 x 2

Something like this?

$m = 2; 
$n = 2; 

for($i = 1; $i <= $m; $i++) {
    for($j = 1; $j <= $n; $j++) {
         echo $i." x ".$j."\n"; 
    }
}

Results:

1 x 1
1 x 2
2 x 1
2 x 2
把梦留给海 2024-12-03 17:48:53

您只想迭代一个二维数组。在伪代码中你会做类似的事情:

for ( i = 0; i < M; i++ ) {
  for ( j = 0; j < N; j++ ) {
    do stuff with array element i,j
  }
}

You just want to iterate through a 2-dimensional array. In pseudocode you'd do something like:

for ( i = 0; i < M; i++ ) {
  for ( j = 0; j < N; j++ ) {
    do stuff with array element i,j
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文