给出代码

#include <stdio.h>
#include <unistd.h>
#include <iostream>
#include <memory.h>
#include <string.h> int main()
{
typedef int data_type;
data_type a[] = {1,4,6,7,7,8,4,9,1,7,6,4,1,2,0,0}; const char* hint = "The original number is:\n ";
write(STDOUT_FILENO, hint, strlen(hint));
for(int i = 0; i < sizeof(a)/sizeof(a[0]); ++i)
{
printf("%d ", a[i]);
}
printf("\n"); // get the max value
int max = a[0];
for(int i = 0;i < sizeof(a)/sizeof(data_type);++i)
{
if(a[i] > max)
{
max = a[i];
}
} // allocate an space. you can use bitwise if the space is too big.
data_type* p = new data_type[max + 1];
memset(p, 0, max + 1); int cnt = 0;
for(int i = 0;i < sizeof(a)/sizeof(data_type);++i)
{
if(*(p + a[i]) == -1)
{
++cnt;
}
else
{
*(p + a[i]) = -1;
}
} std::cout << "The dumplicated number is " << cnt << std::endl; return 0;
}

  

编译执行

[root@ba algr]# g++ array.cpp -g
[root@ba algr]# ./a.out
The original number is:
1 4 6 7 7 8 4 9 1 7 6 4 1 2 0 0
The dumplicated number is 8
[root@ba algr]#

  

最新文章

  1. centos-lynx
  2. 你所不了解的setTimeout
  3. Java Hour 47 WeatherInfo 保存到数据库
  4. web 模板 类似京东左侧的导航栏
  5. DATASNAP REST WEBSERVICES中间件如何跨平台使用
  6. sqlserver 导入/导出Excel
  7. MAC OX 配置JDK环境变量
  8. C#中HashTable的用法示例2
  9. jdbc调用mysql存储过程实现代码带有输入和输出
  10. ftk学习记录(IME文章)
  11. How to:如何在调用外部文件时调试文件路径(常见于使用LaunchAppAndWait和LaunchApp函数)
  12. 基于JQuery EasyUI的WebMVC控件封装(含源码)
  13. Mybatis(四)关联映射
  14. dotnetcore vue+elementUI 前后端分离架二(后端篇)
  15. eclise开发设置
  16. Mac CLion下OpenGL环境配置
  17. .gitignore无效的原因
  18. C++11 constexpr常量表达式
  19. oracle中scott/tiger、sys、SYSDBA、system都是什么用
  20. 如何合理命名CSS文件——摘自网友

热门文章

  1. OpenTK学习笔记
  2. MySQL新参数log_error_verbosity
  3. pip install PIL The _imagingft C module is not installed
  4. Maven替换为国内仓库
  5. Python高级应用(3)—— 为你的项目添加验证码
  6. 前后端分离djangorestframework——ContentType组件表
  7. 理解ECS的概念和Unity中的ECS设计
  8. SpringMVC相关常用注解
  9. linux 硬盘满了如何处理(转)
  10. LeetCode算法题-Repeated String Match(Java实现)