C++
codesailor
水手
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C++Primer 练习11.4
int main(int argc,char **argv) { map<string, size_t> word_count; set<string> exclude = { "and","or","but","the" }; string word; ifstream in("ss.txt"); while (in >&原创 2018-09-24 11:42:50 · 282 阅读 · 0 评论 -
AES密码算法C实现
一、实验题目:做实验并写实验报告。修改例程cryptoDemo.cpp为encfile.cpp :从命令行接受3个字符串类型的参数:参数1,参数2,参数 3。参数1=encrypt表示加密,参数2=decrypt表示解密;参数2为待加密 、解密的文件名;参数3为密码。 二、实验步骤:1、修改镜像源为科大的,然后更新所有应用sudo vi /etc/apt/s...原创 2018-10-07 16:28:27 · 1756 阅读 · 0 评论 -
自定义一个动态分配的vector类
#include "pch.h"#include <iostream>#include <string>using namespace std;class StrVec {public : StrVec() :elements(nullptr), first_free(nullptr), cap(nullptr) {} StrVec(const Str...原创 2018-10-08 20:40:28 · 499 阅读 · 0 评论 -
c++primer 第十三章 拷贝构造函数、拷贝赋值函数、=default、删除函数、析构函数
拷贝构造函数是什么?拷贝构造函数是用来定义 同类型的另一个对象初始化本对象时,所做的工作。它的函数写法是class F{public: F(const F&){};}:如果没有定义拷贝构造函数,编译器会定义默认的合成拷贝构造函数。拷贝赋值运算符:定义将一个对象赋值给同类型的另一个对象时,所做的类所做的工作。operator=class F{...原创 2018-09-29 22:25:16 · 2878 阅读 · 0 评论 -
不用四则运算求a+b
万同学提出了一个问题,怎么不用+号实现a+b。这其实是一个组成原理的问题,也就时加法器是如何实现的。在计算机中,所有的数字都是二进制数进行存储的,你看到的十进制数,实际上是做了做了转换,才让你看的见。所以可以直接使用位运算符号操作两个加数。附上万同学的源代码:int sumab(int a, int b){ if (a == 0) return b; if (b == 0)...原创 2018-09-30 10:29:42 · 314 阅读 · 1 评论 -
Sherwood算法
表示算法A对输入实例的处理时间。算法A对输入规模n的实例的平均处理时间,假如存在一个实例,使得,那么这个算法A就可以进行Sherwood改进。Sherwood算法可以消除最坏实例。参见...原创 2018-10-10 16:13:03 · 1192 阅读 · 0 评论 -
c++将字符转换成字符串
char c;string str;stringstream stream;stream << c;str = stream.str();原创 2018-10-19 22:54:38 · 10145 阅读 · 0 评论 -
暴力回文串
#include "pch.h"#include <iostream>#include <vector>#include <algorithm>#include <string>#include <stack>#include <sstream>using namespace std;int isHui原创 2018-10-19 23:12:25 · 163 阅读 · 0 评论 -
确定性算法A查找链表中的x下标
ch11.ppt P59 #include "pch.h"#include <iostream>#include <random>#include <vector>#include <ctime>#include <algorithm>#define MAXN 10000using namespace std;//...原创 2018-10-10 22:25:59 · 262 阅读 · 0 评论 -
c++微秒级随机数
这种方法可以获取cpu周期时间,精确到微秒__declspec (naked) unsigned __int64 GetCpuCycle(void){ _asm { rdtsc ret }}//返回 2 到 n-2的随机数,n>4int uniform(int n) { unsigned __int64 iCpuCycle = GetCpuCycle(); u...原创 2018-11-09 11:30:38 · 1596 阅读 · 0 评论 -
验证素数的一种方法
bool Btest(int a, int n) { int s = 0, t = n - 1; do { ++s; t /= 2; } while (t % 2 == 1); int x = int(pow(a, t)) % n; if (x == 1 || x == n - 1)return true; for (int i = 1; i <= s - 1; ...原创 2018-11-08 23:00:12 · 478 阅读 · 0 评论 -
error: ‘to_string’ was not declared in this scope
原因是因为g++当前版本g++没有支持c++11,需要在编译时添上-std=c++11eg:原创 2018-12-13 16:55:17 · 2630 阅读 · 0 评论 -
n皇后概率算法与确定算法折衷考虑最后解法
#include "pch.h"#include <iostream>#include <vector>#include <random>#include <ctime>#include <time.h>#include <set>#include <sys/timeb.h>原创 2018-10-13 20:56:20 · 472 阅读 · 0 评论 -
20皇后的不是很正确的解法
// HomeWork_P72.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include "pch.h"#include <iostream>#include <vector>#include <random>#include <ctime>#include <time.h>原创 2018-10-13 19:42:05 · 335 阅读 · 2 评论 -
Las Vegas算法八皇后问题最好的一种实现
#include "pch.h"#include <iostream>#include <vector>#include <random>#include <ctime>#include <time.h>#include <set>#include <sys/timeb.h>u原创 2018-10-13 14:56:30 · 1233 阅读 · 0 评论 -
set multiset
int main(int argc,char **argv) { vector<int> ive; for (auto i = 0; i != 10; ++i) { ive.push_back(i); ive.push_back(i); } set<int> iset(ive.cbegin(), ive.cend()); multiset<int...原创 2018-09-24 13:33:46 · 132 阅读 · 0 评论 -
c++primer 练习11.7
int main(int argc,char **argv) { map<string, vector<string>> imap; //ifstream in("ss.txt"); string fname, gname; cout << "input your family name:\n"; while (cin >> fnam...原创 2018-09-24 15:03:24 · 270 阅读 · 0 评论 -
c++primer 练习11.9 (读取一行字符串,然后从字符串中提取单词)
#include "pch.h"#include <iostream>#include <fstream>#include <vector>#include <algorithm>#include <string>#include <list>#include <iterator>原创 2018-09-24 15:54:24 · 2101 阅读 · 0 评论 -
c++primer 练习11.4
int main(int argc,char **argv) { ifstream in("ss.txt"); string line; vector<pair<string,int>> vec; while (getline(in, line)) { string s; int i; istringstream ss(line); ss >...原创 2018-09-24 16:39:27 · 311 阅读 · 0 评论 -
C++Primer 练习11.12
/**author @alex*title C++Primer 练习11.12*/int main(int argc,char **argv) { ifstream in("ss.txt"); string line; vector<pair<string,int>> vec; while (getline(in, line)) { string s...原创 2018-09-25 09:38:07 · 180 阅读 · 0 评论 -
C++Primer 练习11.20
/**author @alex*title C++Primer 练习11.20*/int main(int argc, char **argv) { map<string, int> word_count; string word; ifstream in("ss.txt"); while (in >> word) { auto ret = wo...原创 2018-09-25 10:13:05 · 187 阅读 · 0 评论 -
C++Primer 练习11.31
/**author @alex*title C++Primer 练习11.31*/int main(int argc, char **argv) { multimap<string, string> immp = { {"k","1"},{"k","2"},{"d","1"} }; for (auto pos = immp.equal_rang原创 2018-09-25 10:57:09 · 267 阅读 · 0 评论 -
C++Primer 练习11.33 单词转换程序
/**author @alex*title C++Primer 练习11.33 单词转换程序*/map<string, string> buildMap(ifstream &map_file) { map<string, string> trans_map; string key; string value; while (map_file >...原创 2018-09-25 11:45:11 · 270 阅读 · 0 评论 -
C++Primer 练习12.6
/**author @alex*title C++Primer 练习12.6*/vector<int>* f1() {//返回一个动态分配的int的vector vector<int> *p = new vector<int>; return p;}vector<int>* f2(){//从标准输入中读取值保存到vector中...原创 2018-09-25 20:37:02 · 189 阅读 · 0 评论 -
12章最后一节的程序
#include "pch.h"#include <iostream>#include <string>#include <vector>#include <map>#include <set>#include <sstream>#include <fstream>using原创 2018-09-27 17:33:26 · 173 阅读 · 0 评论 -
c++随机数的问题
今天写LV算法,就是我之前的那个blog,产生了困扰我很久的问题。使用回溯法计算八皇后,只需要访问114个节点就可以找到一个解。用随机算法理论上,效果比回溯法好,大概只需要访问50几次就可以得到一个解。但是我的随机算法却跑了很久,十几秒。searchNode数在几千到几十万不等。出现这种问题的原因是,随机算法设置的种子time(0)是一个秒级的数,计算机执行随机算法很快,大概是微秒级,所以...原创 2018-10-13 14:48:06 · 779 阅读 · 0 评论 -
c++读写文件
总是忘记,还是记下来,以备以后查看头文件#include <fstream>从文件中读取数据ifstream fin;int i, j;fin.open("datingTestSet.txt");if (!fin) { cout << "cannot open file !" << endl; exit(0);}string ...原创 2018-12-13 21:07:12 · 296 阅读 · 0 评论
分享