/** Read.cpp**  Created on: 2018年8月17日*      Author: admin*/
#include<string.h>
#include<json/json.h>
#include<stdlib.h>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<time.h>
#include<random>
using namespace std;
map<int,string> first_name_map;
map<int,string> man_second_name_map;
map<int,string> man_thired_name_map;
map<int,string> girl_second_name_map;
map<int,string> girl_thired_name_map;
string Get_Random_Name(int sex)
{string name;name = first_name_map[rand()%first_name_map.size()];if(sex==1){if(rand()%2==0)name+=man_second_name_map[rand()%man_second_name_map.size()];name+=man_thired_name_map[rand()%man_thired_name_map.size()];}else{if(rand()%2==0)name+=girl_second_name_map[rand()%girl_second_name_map.size()];name+=girl_thired_name_map[rand()%girl_thired_name_map.size()];}return name;
}
void ReadFileJson();
int main()
{ReadFileJson();int sex;time_t now;time(&now);int starttime = now;cin>>sex;int Max_num = max(man_second_name_map.size()*man_thired_name_map.size(),girl_second_name_map.size()*girl_thired_name_map.size());Max_num*=first_name_map.size();for(int i=0;i<Max_num*3;i++){string name = Get_Random_Name(i);cout<<name<<endl;if(name=="**梅"){time(&now);int Cost_Time = (int)now - starttime;cout<<Cost_Time+'S'<<endl;break;}}return 0;
}
void ReadFileJson()
{Json::Value root;Json::Reader reader;ifstream in("/home/admin/桌面/random_name.json");if(!in.is_open()){cout<<"error to open file!!!"<<endl;return ;}if(reader.parse(in,root)){first_name_map.clear();man_second_name_map.clear();man_thired_name_map.clear();girl_thired_name_map.clear();girl_second_name_map.clear();int sz = 0;sz = root["first_name"].size();for(int i=0;i<sz;i++)first_name_map[i] = root["first_name"][i].asString();sz = root["man_second"].size();for(int i=0;i<sz;i++)man_second_name_map[i] = root["man_second"][i].asString();sz = root["man_third"].size();for(int i=0;i<sz;i++)man_thired_name_map[i] = root["man_third"][i].asString();sz = root["woman_second"].size();for(int i=0;i<sz;i++)girl_second_name_map[i] = root["woman_second"][i].asString();sz = root["woman_third"].size();for(int i=0;i<sz;i++)girl_thired_name_map[i] = root["woman_third"][i].asString();}
}

七夕快乐,这个算是在公司写的最后一段代码吧,人生有梦,各自精彩。

C++读取Json生成随机名字相关推荐

  1. sqlserver 人名_mssql sqlserver 使用sql脚本生成随机中文名字的方法分享

    摘要: 下文使用sql脚本生成中文名字的方法分享,如下所示: 实验环境:sql server 2008 R2 在工作中,我们有时需要批量生成随机姓名,下面将讲述使用sql脚本生成随机"名字& ...

  2. Java工具类-生成随机汉字和名称

    将代码复制到你的项目中,运行test方法即可看到效果 import org.junit.Test;import java.io.UnsupportedEncodingException; import ...

  3. 随机名字生成小demo源码

    根据提供的文字随机生成指定字符的名称,挺简单的,一个小demo吧 源字符 package com.example.demo;import cn.hutool.core.util.RandomUtil; ...

  4. 【SQL Server 学习系列】-- sql 随机生成中文名字

    [SQL Server 学习系列]-- sql 随机生成中文名字 原文:[SQL Server 学习系列]-- sql 随机生成中文名字 1 DECLARE @fName TABLE(Id INT I ...

  5. qt先生成json文件后程序启动时读取json文件在一组数据模拟下正常,换一组数据就出现乱码

    提要 程序编号后自己模拟的数据程序在生成和解析json时都正常,但是换了一组数据,生成的json文件中部分中文乱码,且出现json文件的格式被混乱的现象. 效果 上述出现的不正确的json文件,如下: ...

  6. 利用random随机生成汉字名字

    利用random库生成汉字: 姓氏也可以按照随机生成字来使用,不过本文中姓氏固定了列表汉字 代码: import random names = [] def generate_name(n):#随机姓 ...

  7. [torchtext]如何利用torchtext读取json文件并生成batch

    如何利用torchtext读取json文件并生成batch 设置Field 使用torchtext.data.Tabulardataset.splits读取文件 构建vocab表 使用torchtex ...

  8. 【Java】基于JSON-Schema生成随机JSON的解决方案

    一.需求 1.给出特定格式json-schema,生成随机json串 2.json串,目录结构按json-schema定义 3.使用java开发语言 4.不需要提供页面,能输出随机json串即可(控制 ...

  9. 用java随机生成中文名字(百家姓/常用名/随机生成汉字)

    package com.de.util;import org.apache.commons.collections.CollectionUtils; import org.apache.commons ...

最新文章

  1. dlib 68个关键点 人脸姿态
  2. 【Flask】ORM的关联关系
  3. dask 使用_在Google Cloud上使用Dask进行可扩展的机器学习
  4. postmapping注解参数说明_从零搭建后端框架:优雅的参数校验Validator
  5. ptcms精美小说阅读网站源码(带采集规则)
  6. Unity脚本各种[XXX]的用法
  7. python编程教学软件-【掌控】mPython编程与教学软件平台汇总
  8. 最新基于CentOS 5.5 ,集成lamp,lnmp终级安装版
  9. 计算机设备故障,计算机常见硬件故障及其原因
  10. java生成word并导出pdf
  11. 分享55个计数统计PHP源码,总有一款适合你
  12. 朴素贝叶斯解决凉鞋问题
  13. 关于加速器加速后进入游戏显示WiFi功能丢失的解决方法(maybe)
  14. Keras中verbose的作用
  15. Linux文件锁(Filelock)是什么,怎么用?
  16. PCIe系列专题之一:PCIe技术概述
  17. apexError计算机离线状态,Apex英雄第六赛季常见故障排除方法
  18. 51单片机 按键控制LED流水灯模式
  19. m5stack——基于语音交互模块的物联居家管理系统 (STM32F103ZET6开发板+UART通信)
  20. insmod: error inserting 'vivi.ko': -1 Unknown symbol in module 问题解决办法

热门文章

  1. @Scheduled不执行的原因
  2. Qt学习之路(51): QByteArray和QVariant
  3. 删除某文件以外的文件
  4. Promise 源码:静态方法
  5. Spring Cloud Spring Boot mybatis分布式微服务云架构(五)构建RESTful API
  6. Android 获取手机的厂商、型号、Android系统版本号、IMEI、当前系统语言等工具类...
  7. Linux设备模型(9)_device resource management ---devm申请空间【转】
  8. [leetcode]Largest Rectangle in Histogram @ Python
  9. Go http访问使用代理
  10. 信息收集--IP扫描 (上篇)