学习复习下数字字符算法使用

hongwenjun 2016-11-10 10:45:01
#include <stdio.h>      // 定义输入/输出函数
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <time.h> /* time */
#include <stdlib.h>

int main()
{
int x = 0 ;
int number[10];
char buf[32];
srand(time(NULL)); // 随机序列种子

// 100个随机数 , 判断由哪些自然数组成
for (int j = 0; j != 100; ++j) {
x = rand();

sprintf(buf, "%d", x); // 数字转成字符串

std::sort(buf, buf + strlen(buf)); // 排序
auto it = std::unique(buf, buf + strlen(buf)); // 删除重复的数字
*it = '\0';

printf("%d: [ ", x); // 字符转成数字打印出来
for (int i = 0; i != strlen(buf) ; ++i) {
number[i] = buf[i] - '0';
printf("%d ", number[i]);
}
printf("]\n");

}
return 0;
}




...全文
131 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-11-11
  • 打赏
  • 举报
回复
引用 4 楼 hongwenjun 的回复:
[quote=引用 3 楼 zhao4zhong1 的回复:] http://www.cplusplus.com
cplusplus-2013-8-8.chm 这个 chm是我做的,学C++ 一般够用了[/quote]
hongwenjun 2016-11-11
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
http://www.cplusplus.com
cplusplus-2013-8-8.chm 这个 chm是我做的,学C++ 一般够用了
赵4老师 2016-11-11
  • 打赏
  • 举报
回复
小灸舞 2016-11-11
  • 打赏
  • 举报
回复
paschen 版主 2016-11-10
  • 打赏
  • 举报
回复

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧