MWE: 让我们考虑以下示例.
L0=[[b,0],[b,b]], L1=[[b,b],[b,1]], L2=[[b,b],[2,b]]
S=[[0,1,2],[2,0,1]]
Run Code Online (Sandbox Code Playgroud)
是否有任何方法将S的每个元素替换为L0为0,L1替换为1,L2替换为2以获得S1,如图所示?

实际上,我想要一个python程序来检查:如果S的元素为零,那么它将由预定义的2D数组替换0,依此类推.
下面的程序为负整数和零整数给出正确的结果,但是对于正整数,它给出错误的输出:
Enter the value of a : 6
The no is positive
The no is zero
Run Code Online (Sandbox Code Playgroud)
为什么?
int main()
{ int a;
printf("Enter the value of a : ");
scanf("%d",&a);
if(a>0)
printf("The no is positive\n");
if(a<0)
printf("The no is negative\n");
else
printf("The no is zero\n");
}
Run Code Online (Sandbox Code Playgroud) 我得到了意想不到的输出,我无法弄清楚原因。
#include <stdio.h>
int main() {
int a = 0100;
int b = 010;
int c = 1111;
int d = 01111;
printf("0100 => %d, 010 => %d, 1111 => %d, 01111=> %d\n", a, b, c, d);
}
Run Code Online (Sandbox Code Playgroud)
输出:
0100 => 64, 010 => 8, 1111 => 1111, 01111=> 585
Run Code Online (Sandbox Code Playgroud)
为什么会出现这样的输出?