babyname.bmp
如果懒得自己编译的就下载此“图片”,重命名为exe后缀即可直接使用
===============================================================================
#include <iostream>
#include <cstdio>
#include <ctime>
using namespace std;
void usage()
{
cout << "usage : babyname.exe [姓] [名字候选字] [0 or other : 随机顺序 or 正序] [0 or other : 去除叠字名 or 不去除]" << endl;
cout << "example : babyname.exe 张 三四五 0 0" << endl;
}
void output_one_name(char* family_name, char* names, int first_pos, int second_pos)
{
cout << family_name << names[first_pos*2] << names[first_pos*2+1] << names[second_pos*2] << names[second_pos*2+1] << endl;
}
int rand_int(int min, int max)
{
int i = ((rand() % 2) << 30);
i |= (rand() << 15);
i |= rand();
return (i % (max - min + 1)) + min;
}
int main(int argc, char* argv[])
{
if (argc != 5)
{
usage();
return 1;
}
int name_cand_cnt = strlen(argv[2]);
if (name_cand_cnt % 2 != 0)
{
cout << "名字候选字必须为中文" << endl;
return 1;
}
name_cand_cnt /= 2;
bool random_flag = (strcmp(argv[3], "0") == 0);
bool forbid_double_flag = (strcmp(argv[4], "0") == 0);
if (random_flag)
{
if (name_cand_cnt > 10240)
{
cout << "名字候选字太多,请不要使用随机顺序" << endl;
return 1;
}
int cand_cnt = name_cand_cnt * name_cand_cnt;
int* order = new int[cand_cnt];
for (int i = 0; i < cand_cnt; i++)
{
order[i] = i;
}
srand((unsigned)time(NULL));
for (int i = 1; i < cand_cnt; i++)
{
int swap_pos = rand_int(0, i);
if (swap_pos != i)
{
int tmp = order[i];
order[i] = order[swap_pos];
order[swap_pos] = tmp;
}
}
for (int i = 0; i < cand_cnt; i++)
{
int first_pos = order[i] / name_cand_cnt;
int second_pos = order[i] % name_cand_cnt;
if (!forbid_double_flag ||
first_pos != second_pos)
{
output_one_name(argv[1], argv[2], first_pos, second_pos);
}
}
delete[] order;
}
else
{
for (int i = 0; i < name_cand_cnt; i++)
{
for (int j = 0; j < name_cand_cnt; j++)
{
if (!forbid_double_flag ||
i != j)
{
output_one_name(argv[1], argv[2], i, j);
}
}
}
}
return 0;
}
如果懒得自己编译的就下载此“图片”,重命名为exe后缀即可直接使用
===============================================================================
#include <iostream>
#include <cstdio>
#include <ctime>
using namespace std;
void usage()
{
}
void output_one_name(char* family_name, char* names, int first_pos, int second_pos)
{
}
int rand_int(int min, int max)
{
}
int main(int argc, char* argv[])
{
}