随机生成字符串
2017-10-20 11:55
113 查看
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL; struct Node { double val; int ran; char ch; bool operator < (const Node & rhs) const { if (val != rhs.val) return val < rhs.val; else return ran > rhs.ran; } Node(double _val, int _ran, char _ch) { val = _val, ran = _ran, ch = _ch; } }; priority_queue<Node> que; const int maxn = RAND_MAX + 20; bool vis[maxn]; map<unsigned long long int, bool> mp; char str[22222]; const int seed = 131; void show() { static int f = 0; if (f < 100) printf("f\n"); else exit(-1); f++; } void work() { srand(time(NULL)); for (int i = 'a'; i <= 'z'; ++i) { int ran = rand(); while (vis[ran]) ran = rand(); vis[ran] = true; que.push(Node(1e18, ran, i)); } for (int i = '0'; i <= '9'; ++i) { int ran = rand(); while (vis[ran]) ran = rand(); vis[ran] = true; que.push(Node(1e18, ran, i)); } int ansNum, ansLen; printf("please enter the number for Code : "); scanf("%d", &ansNum); printf("please enter the len for Code : "); scanf("%d", &ansLen); for (int i = 1; i <= ansNum; ++i) { unsigned long long int hashVal = 0; for (int j = 1; j <= ansLen; ++j) { Node t = que.top(); que.pop(); str[j] = t.ch; t.val /= 2; vis[t.ran] = false; int en = rand(); while (vis[en] == true) { // show(); en = rand(); // printf("%d\n", en); } t.ran = en; que.push(t); hashVal = hashVal * seed + t.ch; } if (!mp[hashVal]) { mp[hashVal] = true; printf("%s\n", str + 1); } else { i--; } } } int main() { work(); return 0; }
View Code
相关文章推荐
- Rails生成随机字符串及加解密
- javascript自动生成包含数字与字符的随机字符串
- Java生成随机字符串
- 如何随机生成01随机字符串
- JQuery生成随机字符串
- Excel生成随机字符串(数字大小写混合)
- java生成随机字符串
- 随机字符串的生成
- 用ASP编程语言实现生成随机字符串
- java 微信支付随机字符串生成方法
- 【转】MySQL随机字符串生成
- 随机验证码生成(生成一个含有n位随机数字的字符串)
- 生成n位随机字符串(转)
- 随机生成给定长度的字符串,并且不重复
- 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间
- 编写多线程程序,模拟多个人通过一个山洞。这个山洞每次只能通过一个人,每个人通过山洞的时间为2秒(sleep)。随机生成10个人,都要通过此山洞,用随机值对应的字符串表示人名,打印输出每次
- 也来个c#随机生成字符串
- C++ 随机生成数字和字母组合的字符串
- java随机数生成1到10 java怎么随机生成一个字符串?
- Python生成8位随机字符串的一些方法 分类: python学习 2015-04-28 20:00 62人阅读 评论(0) 收藏