加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
4-17.c 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
王振宇 提交于 2022-04-17 21:47 . 牛客
#define _CRT_SECURE_NO_WARNINGS 1
//BC125 序列中整数去重
#include <stdio.h>
int main()
{
int n = 0;
int m = 0;
int i = 0;
int c = 0;
int count = 0;
int arr1[1000] = { 0 };
int arr2[1000] = { 0 };
scanf("%d", &n);
int k = n;
while (k--)
{
scanf("%d", &m);
arr1[i] = m;
i++;
}
for (int i = 0; i < n; i++)
{
count = 0;
for (int j = 0; j <= i; j++)
{
if (arr1[i] == arr2[j])
{
count++;
break;
}
}
if (count == 0)
{
arr2[c] = arr1[i];
c++;
}
}
for (int z = 0; z < c; z++)
printf("%d ", arr2[z]);
return 0;
}
//BC126 小乐乐查找数字
#include <stdio.h>
int main()
{
int n = 0;
int m = 0;
int i = 0;
int s = 0;
int count = 0;
int arr[100] = { 0 };
scanf("%d", &n);
int k = n;
while (k--)
{
scanf("%d", &m);
arr[i] = m;
i++;
}
scanf("%d", &s);
for (int j = 0; j < n; j++)
{
if (arr[j] == s)
count++;
}
printf("%d", count);
return 0;
}
//BC127 筛选法求素数
#include <stdio.h>
int main()
{
int n = 0;
int s = 0;
int count = 0;
int arr[100] = { 0 };
while (~scanf("%d", &n))
{
for (int i = 2; i <= n; i++)
{
count = 0;
for (int j = 2; j <= i / 2; j++)
{
if (i % j == 0)
{
count++;
break;
}
}
if (count == 0)
{
arr[s] = i;
s++;
}
}
for (int i = 0; i < s; i++)
printf("%d ", arr[i]);
printf("\n%d", n - 1 - s);
}
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化