64,642
社区成员
发帖
与我相关
我的任务
分享
#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;
}