题解 | #序列中删除指定数字#

序列中删除指定数字

https://www.nowcoder.com/practice/7bbcdd2177a445a9b66da79512b32dd7

#include <stdio.h>
#include<stdlib.h>
int main()
{
	int N;
	scanf("%d", &N);
  //动态内存分配
	int* arr = (int*)malloc(N * sizeof(int));
	int* a = (int*)malloc(N * sizeof(int));
	if (a == NULL || arr == NULL)//printf("内存分配失败\n");
	{
		free(a);
		free(arr);
		return 1;
	}
	int i;
	for (i = 0; i < N; i++)
		scanf("%d ", &arr[i]);
	int del = 0;
	scanf("%d", &del);
	int j = 0;
	for (i = 0; i < N; i++)
	{
		if (arr[i] != del)
		{
			a[j++] = arr[i];
		}
	}
	for (i = 0; i < j; i++)
		printf("%d ", a[i]);
	free(a);
	free(arr);
	return 0;
}

全部评论

相关推荐

zzzzhz:兄弟你先猛猛投简历至少三百家,能约到面试就去面。最近可以速成智能小车,智慧家居烂大街的项目,不需要自己写,只需要把里面的代码讲解看明白就行。把其中涉及到的八股文都拿出来单独背一下,我去年找工作就一个智能小车智慧家居找了10k差不多。
点赞 评论 收藏
分享
猫头夜鹰:图书管理系统能有面试就怪了,放十年前都不行
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务