360网站 备案,我想做个网站推广怎么做,电子商务网站建设品牌,h5应用本文记录了两道代码题【自除数】和【除自身以外数组的乘积】#xff08;利用了前缀积和后缀积#xff0c;值得再看#xff09;#xff0c;第二部分记录了关于指针数组和逗号表达式的两道选择题。 每日代码 自除数
. - 力扣#xff08;LeetCode#xff09;
/*** Note: T…本文记录了两道代码题【自除数】和【除自身以外数组的乘积】利用了前缀积和后缀积值得再看第二部分记录了关于指针数组和逗号表达式的两道选择题。 每日代码 自除数
. - 力扣LeetCode
/*** Note: The returned array must be malloced, assume caller calls free().*/
int div_self(int x) {if (x 0)return 0;int num x;while (x) {int bit x % 10;if (bit 0)return 0;if (num % bit ! 0)return 0;x / 10;}return 1;
}
int* selfDividingNumbers(int left, int right, int* returnSize) {int* returnnums (int*)malloc(sizeof(int)*(right - left 1));int pos 0;for (int i left; i right; i) {if (div_self(i))returnnums[pos] i;}*returnSize pos;return returnnums;
} 除自身以外数组的乘积
. - 力扣LeetCode /*** Note: The returned array must be malloced, assume caller calls free().*/
int* productExceptSelf(int* nums, int numsSize, int* returnSize) {int *ans malloc(sizeof(int) * numsSize);*returnSize numsSize;ans[0] 1;for (int i 1; i numsSize; i) {ans[i] ans[i - 1] * nums[i - 1];}int suf 1;for (int i numsSize - 1; i 0; i--) {ans[i] * suf;suf * nums[i];}return ans;
}
利用前缀积和后缀积。很遗憾代码是搬来的只懂了思路明天一定要亲自运行出来 C语言碎片知识 下列程序的输出是 #includestdio.h
int main()
{int a [12] {1,2,3,4,5,6,7,8,9,10,11,12}*p[4],i;for(i0;i4;i)p[i]a [i*3];printf(%d\np[3][2]);return 0;
} A: 上述程序有错误 B: 6 C: 8 D: 12 答案D
p是一个指针数组数组里存放的是指针分别存放了a[0],a[3],a[6],a[9]的地址。类似于一个四行三列的数组。 以下逗号表达式的值为 (x 4 * 5 , x * 5) , x 5; A: 25 B: 20 C: 100 D: 45 答案A
逗号表达式从前往后计算结果为最后一项的值题目等价于x20,20*5,205。x*5时也并没有改变x的值。 -The End-