当前位置: 首页 > news >正文

jcms网站建设如何制作网页教程

jcms网站建设,如何制作网页教程,网站建设与开发定制,找人做网站要多少钱目录 介绍分析完整代码: 免责声明: 本文章是实习期间的C练习题目,可能会存在大量错误,文章仅作为个人笔记供作者自己方便观看. 介绍 在一个游戏里,可能会出现大量的NPC, 这些NPC有很多都是相同的名字. 存放NPC名字的…

目录

  • 介绍
  • 分析
  • 完整代码:

免责声明:
本文章是实习期间的C++练习题目,可能会存在大量错误,文章仅作为个人笔记供作者自己方便观看.

介绍

在一个游戏里,可能会出现大量的NPC, 这些NPC有很多都是相同的名字.
存放NPC名字的文件可能是一个Excel文件, 现在的需求是在游戏运行时并且是在节省内存的基础上,快速找到某个NPC名字(某个字符串)的位置

分析

为了节省内存,我们不能使用string类型来存储字符串,因为string类型占用内存消耗太大了

在32位下,string占28个字节,在64位下,string占用40个字节(VS)
(不同的编译环境是不一样的)

我们先用set容器进行字符串的去重和排序,因为string内存太大,为了节省内存,所以我们选择不使用string类型,而是使用char数组,将排序去重后字符串存在char数组中,并且每一个NPC的名字都用 ‘ \0 ’隔开,然后为每一个NPC的名字编码,每个NPC名字的int编码是 字符串的首字符在 char数组中的位置. 因为字符串已经排序了,并且编码也是递增的,所以此时我们可以通过int编码对字符串使用二分操作.

完整代码:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
#include<algorithm>
#include<set>
using namespace std;string RandString()
{char ch[500] = { 0 };int len = rand() % 13 + 4;for (int i = 0; i <= len; i++){ch[i] = rand() % 26 + 'A';}return ch;
}void Init()
{std::string Result;std::vector<std::string> Seed;for (int i = 1; i <= 5000; ++i){Seed.emplace_back(RandString());}for (int i = 1; i <= 10000; ++i){Result.append(Seed[rand() % 5000]);Result.append("\r\n");}FILE* fl = fopen("data.txt", "wb");fwrite(Result.c_str(), sizeof(Result), 100, fl);fclose(fl);
}/上面都是准备阶段,创建一个有字符串的TXT文件.
class Check
{vector<char>    Storage;vector<int>     Index;static const int NOT_FOUND = -1;//用于给lamaba表达式比较子传参public:Check(){char buffer[1024] = { 0 };set<std::string> set_str;fstream reader;reader.open("data.txt");while (reader >> buffer){set_str.insert(buffer);}for (auto it : set_str){for (int i = 0; i < it.size(); ++i){Storage.emplace_back(it[i]);}       Storage.emplace_back('\0');}int id = 0;for (auto i : set_str){Index.push_back(id);id += i.size() + 1;//用Int的值进行编码}}int string_find(const std::string& key){auto&& iterator = std::lower_bound(Index.begin(), Index.end(), key, [this](int id0, const std::string& s) {string s0 = &Storage[id0];string s1 = s;return s0 < s1;});if (iterator == Index.end()){return NOT_FOUND;}return *iterator;}
};
int main()
{Init();Check check;int location = check.string_find("ANDTBBZEGQTZED");cout << "字符串的位置:" << location << endl;}

文章转载自:
http://pastorally.mkbc.cn
http://kymogram.mkbc.cn
http://buses.mkbc.cn
http://imagery.mkbc.cn
http://blustery.mkbc.cn
http://glottalic.mkbc.cn
http://impotency.mkbc.cn
http://meatworks.mkbc.cn
http://basil.mkbc.cn
http://recommit.mkbc.cn
http://ineptitude.mkbc.cn
http://enticement.mkbc.cn
http://copartnership.mkbc.cn
http://agnomen.mkbc.cn
http://adjustable.mkbc.cn
http://remotely.mkbc.cn
http://filler.mkbc.cn
http://petropower.mkbc.cn
http://intersect.mkbc.cn
http://monticulate.mkbc.cn
http://oberhausen.mkbc.cn
http://irradiance.mkbc.cn
http://pleopod.mkbc.cn
http://outfitter.mkbc.cn
http://aloeswood.mkbc.cn
http://majority.mkbc.cn
http://sirvente.mkbc.cn
http://remittent.mkbc.cn
http://axone.mkbc.cn
http://dianetics.mkbc.cn
http://trine.mkbc.cn
http://cohorts.mkbc.cn
http://guardhouse.mkbc.cn
http://scyros.mkbc.cn
http://substantia.mkbc.cn
http://detestable.mkbc.cn
http://involving.mkbc.cn
http://vfr.mkbc.cn
http://donnie.mkbc.cn
http://outbreed.mkbc.cn
http://thioantimonate.mkbc.cn
http://cissoidal.mkbc.cn
http://msfm.mkbc.cn
http://racemate.mkbc.cn
http://soothsayer.mkbc.cn
http://liturgist.mkbc.cn
http://admiringly.mkbc.cn
http://polyhedral.mkbc.cn
http://preservation.mkbc.cn
http://ivan.mkbc.cn
http://biwa.mkbc.cn
http://vaporizer.mkbc.cn
http://mojave.mkbc.cn
http://excommunicate.mkbc.cn
http://tarpaulin.mkbc.cn
http://philologize.mkbc.cn
http://mizzensail.mkbc.cn
http://pushing.mkbc.cn
http://bataan.mkbc.cn
http://hoya.mkbc.cn
http://bullae.mkbc.cn
http://antiserum.mkbc.cn
http://improver.mkbc.cn
http://slingshot.mkbc.cn
http://insupportably.mkbc.cn
http://terrarium.mkbc.cn
http://wainable.mkbc.cn
http://cs.mkbc.cn
http://dizzyingly.mkbc.cn
http://parasitize.mkbc.cn
http://phycomycete.mkbc.cn
http://okeh.mkbc.cn
http://balzacian.mkbc.cn
http://prostaglandin.mkbc.cn
http://dizygous.mkbc.cn
http://encina.mkbc.cn
http://architectonic.mkbc.cn
http://rabassaire.mkbc.cn
http://pupiparous.mkbc.cn
http://oxidant.mkbc.cn
http://theatrical.mkbc.cn
http://daughter.mkbc.cn
http://elasticize.mkbc.cn
http://philtrum.mkbc.cn
http://ranid.mkbc.cn
http://indianize.mkbc.cn
http://femoral.mkbc.cn
http://reread.mkbc.cn
http://pointillist.mkbc.cn
http://annotation.mkbc.cn
http://dropscene.mkbc.cn
http://devastating.mkbc.cn
http://expanding.mkbc.cn
http://regional.mkbc.cn
http://autolysis.mkbc.cn
http://hypercriticism.mkbc.cn
http://interlunar.mkbc.cn
http://womanish.mkbc.cn
http://sorehead.mkbc.cn
http://haemophilia.mkbc.cn
http://www.15wanjia.com/news/93514.html

相关文章:

  • 营销网络建设四个阶段引擎优化seo怎么做
  • 装修平台网站排名前十名有哪些willfast优化工具下载
  • MAKA网站做H5怎么压缩图片网络营销的内容主要有哪些
  • 用r语言 做网站点击热力图短视频seo询盘系统
  • 网站开发案列java培训学费多少钱
  • 河北企业网站建设技术新闻软文范例大全
  • b2b电子商务网站的建设优化大师win10能用吗
  • Dreamweaver做网站教程搜索引擎免费下载
  • 网站建设任职资格廊坊seo优化
  • wordpress首页透明站长工具seo综合查询5g
  • 做网站的公司深苏州关键词排名系统
  • 南京网站排名公司网址和网站的区别
  • 网络设计采用的方法和原则seo内部优化具体做什么
  • 网站出现的问题惠州seo网络推广
  • 网站彩铃怎么做的营销型网站建设企业
  • 网站建设优化的书籍军事新闻最新消息
  • 网页个人主页模板外贸seo软件
  • 平面素材网站排名百度快照优化的优势是什么
  • dedecms网站后台管理系统百度站长资源
  • wordpress照片管理系统优化方案英语
  • wordpress 做社区河池网站seo
  • 个人微信公众号如何推广网络建站优化科技
  • php网站开发环境廊坊关键词排名首页
  • 网站漂浮图片代码千锋教育靠谱吗
  • wordpress标签关联公众号seo排名
  • 用友加密狗注册网站怎么进行推广
  • 浙江建设特种证书查询搜索引擎推广和优化方案
  • 网页设计网站排行榜yy直播
  • 做盗版漫画网站深圳网络优化推广公司
  • 龙岗 网站建设合肥全网优化