begin

c++ vector容器

回眸只為那壹抹淺笑 提交于 2019-12-02 04:56:11
转 http://www.cnblogs.com/Nonono-nw/p/3462183.html # include <vector> 一、vector 的初始化 vector < int > a ( 10 ) ; //定义了10个整型元素的向量(尖括号中为元素类型名,它可以是任何合法的数据类型),但没有给出初值,其值是不确定的。 vector < int > a ( 10 , 1 ) ; //定义了10个整型元素的向量,且给出每个元素的初值为1 vector < int > a ( b ) ; //用b向量来创建a向量,整体复制性赋值 vector < int > a ( b . begin ( ) , b . begin + 3 ) ; //定义了a值为b中第0个到第2个(共3个)元素 int b [ 7 ] = { 1 , 2 , 3 , 4 , 5 , 9 , 8 } ; vector < int > a ( b , b + 7 ) ; //从数组中获得初值 二vector对象的几个重要操作 ( 1 )a . assign ( b . begin ( ) , b . begin ( ) + 3 ) ; //b为向量,将b的0~2个元素构成的向量赋给a ( 2 )a . assign ( 4 , 2 ) ; //是a只含4个元素,且每个元素为2 ( 3 )a . back

MergeSort-vector

孤街浪徒 提交于 2019-12-02 03:30:28
include include using std::cout; using std::endl; using std::vector; void Merge(vector &v, int L, int M, int R) { //拆分成两个vector:left和right //vector(begin,end):复制[begin,end)区间内另一个数组的元素到vector中 vector left(v.begin() + L, v.begin() + M + 1); vector right(v.begin() + M + 1, v.begin() + R + 1); //两个迭代器 auto left_it = left.cbegin(); auto right_it = right.cbegin(); int i = L; //合并vector while (left_it != left.cend() && right_it != right.cend()) { if ( left_it < right_it) v[i++] = (left_it++); else v[i++] = (right_it++); } while (left_it != left.cend()) v[i++] = (left_it++); while (right_it != right

剑指offer 28:字符串的排列

ぃ、小莉子 提交于 2019-12-02 02:02:46
题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。 输入描述 输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。 解题思路 本题解题思路与存在重复数字的数组的全排列思路相同。需要完成排列去重的工作。因而工作分为两步。第一,确定当前数组元素的全排列;第二,对排列结果去重。 1.无论对于数组还是字符串,使用递归实现全排列的过程最容易,对于一个字符串而言,他的所有全排列可视为由第一个字符与剩余所有字符全排列的连接。而对于剩余字符,又可视为剩余字符中第一个字符,与其他剩余字符全排列的连接,依次递归。 2.对于去重,使用哈希地址映射,快速去重,简单讲就是使用set数据类型存储得到的所有全排列,最终set集合中得到的就是去重后的结果。 C++代码实现 class Solution { public: vector<string> Permutation(string str) { vector<string> result; int sz=str.size(); if(sz==0){ return result; } Permutation_sub(str,0,result); set<string> st(result.begin(),

STL lower_bound upper_bound 用法

和自甴很熟 提交于 2019-12-02 00:30:19
1.lower_bound(begin,end,x) 返回第一个>=x的位置,找不到return .end() 2.upper_bound (begin,end,x) 返回第一个>x的位置,找不到return .end() 减掉begin得到下标 vector版 #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> #include<vector> using namespace std; vector<int>a; int b[10]; int main(){ a.push_back(1); a.push_back(1); a.push_back(2); a.push_back(3); int p=lower_bound(a.begin(),a.end(),1)-a.begin(); int q=lower_bound(a.begin(),a.end(),2)-a.begin(); printf("%d %d\n",p,q);// 0 2 p=upper_bound(a.begin(),a.end(),1)-a.begin(); q=upper_bound(a.begin(),a.end(),2)-a.begin();

三十分钟学会AWK

两盒软妹~` 提交于 2019-12-02 00:01:06
本文大部分内容翻译自我开始学习AWK时看到的一篇英文文章 AWK Tutorial ,觉得对AWK入门非常有帮助,所以对其进行了粗略的翻译,并对其中部分内容进行了删减或者补充,希望能为对AWK感兴趣的小伙伴提供一份快速入门的教程,帮助小伙伴们快速掌握AWK的基本使用方式,当然,我也是刚开始学习AWK,本文在翻译或者补充的过程中肯定会有很多疏漏或者错误,希望大家能够帮忙指正。 本文将会持续修正和更新,最新内容请参考我的 GITHUB 上的 程序猿成长计划 项目,欢迎 Star。 概述 AWK是一门解释型的编程语言。在文本处理领域它是非常强大的,它的名字来源于它的三位作者的姓氏: Alfred Aho , Peter Weinberger 和 Brian Kernighan 。 GNU/Linux发布的AWK目前由自由软件基金会(FSF)进行开发和维护,通常也称它为 GNU AWK 。 AWK的类型 下面是几个AWK的变体: AWK - 原先来源于 AT & T 实验室的的AWK NAWK - AT & T 实验室的AWK的升级版 GAWK - 这就是GNU AWK。所有的GNU/Linux发布版都自带GAWK,它与AWK和NAWK完全兼容 AWK的典型用途 使用AWK可以做很多任务,下面是其中一些 文本处理 输出格式化的文本报表 执行算数运算 执行字符串操作等等 工作流

ZROI#1014

偶尔善良 提交于 2019-12-01 22:49:20
ZROI#1014 ZROI#1014 在某位置插入一个数,查询一段区间内所有数异或一个值之后的最大值,这看起来非常的数据结构,事实上这就是一道数据结构题... 题解是怎样的的呢? \(std\) 是这种写法 \(:\) 对时间分块后用可持久化 \(Trie\) 树维护. 不会,咋办?莫慌,我们有万能的 \(vector\) . 在位置 \(pos\) 插入一个数 \(x\) 就 v.insert ( v.begin () + pos - 1 , x ) \(-1\) 的原因是 \(vector\) 的下标从 \(0\) 开始. 查询 \([l,r]\) 中所有数异或一个 \(x\) 的最大值就 \(:\) for (vector < int > :: iterator it = v.begin () + l - 1 ; it != v.begin () + r ; ++ it) ans = max ( ans , ( *it ^ x ) ) ; 为什么初始是 \(v.begin () + l - 1\) 而结束就是 \(v.begin () + r\) 呢? 因为左闭右开,其实还是因为下标从 \(0\) 开始,一个道理. 你可能疑惑,这怎么可能过啊,明明就是 \(\Theta(n^2)\) . 确实...但 \(vector\) 谜一样速度谁也说不清...之前还有 \

导 师 教 你 怎 么 回 血 最 快 最 安 全 的 技 巧

两盒软妹~` 提交于 2019-12-01 20:41:27
【〓⑤⑦⑤⑥⑧③①②〓】邀请玛【①⑤⑧⑧①⑧⑧⑧】官网hct728点c0 m qryStage.First; //链接内部服务器SQL的query qryProductivity.First; //链接外部服务器SQL的query while not qryStage.Eof or qryProductivity.Eof do //此语句是否存在错误?我按照.net的思路来的 begin CDS_Output.Insert; CDS_Outputfac.Value := 'ZD00'; CDS_Outputres.Value := Copy(cbStage.Text,1,3); if not (cbShift.Text = '') then begin if StrToInt(cbStage.Text) in [010,020,030,060] then begin CDS_Outputarea.Value := 'DFZ-POWER-SMD'; end else begin CDS_Outputarea.Value := 'DFZ-POWER-SPI'; end; end; CDS_Outputdate.Value := qryStage.fieldbyname('outputdate').AsInteger; CDS_Outputshift.Value := qryStage

飞 艇 有 没 有 靠 谱 回 血 上 岸 的 导 师

陌路散爱 提交于 2019-12-01 20:41:14
【〓⑤⑦⑤⑥⑧③①②〓】邀请玛【①⑤⑧⑧①⑧⑧⑧】官网hct728点c0 m qryStage.First; //链接内部服务器SQL的query qryProductivity.First; //链接外部服务器SQL的query while not qryStage.Eof or qryProductivity.Eof do //此语句是否存在错误?我按照.net的思路来的 begin CDS_Output.Insert; CDS_Outputfac.Value := 'ZD00'; CDS_Outputres.Value := Copy(cbStage.Text,1,3); if not (cbShift.Text = '') then begin if StrToInt(cbStage.Text) in [010,020,030,060] then begin CDS_Outputarea.Value := 'DFZ-POWER-SMD'; end else begin CDS_Outputarea.Value := 'DFZ-POWER-SPI'; end; end; CDS_Outputdate.Value := qryStage.fieldbyname('outputdate').AsInteger; CDS_Outputshift.Value := qryStage

怎 么 预 防 买 彩 票 上 头 赢 小 输 大

梦想的初衷 提交于 2019-12-01 20:41:06
【〓⑤⑦⑤⑥⑧③①②〓】邀请玛【①⑤⑧⑧①⑧⑧⑧】官网hct728点c0 m qryStage.First; //链接内部服务器SQL的query qryProductivity.First; //链接外部服务器SQL的query while not qryStage.Eof or qryProductivity.Eof do //此语句是否存在错误?我按照.net的思路来的 begin CDS_Output.Insert; CDS_Outputfac.Value := 'ZD00'; CDS_Outputres.Value := Copy(cbStage.Text,1,3); if not (cbShift.Text = '') then begin if StrToInt(cbStage.Text) in [010,020,030,060] then begin CDS_Outputarea.Value := 'DFZ-POWER-SMD'; end else begin CDS_Outputarea.Value := 'DFZ-POWER-SPI'; end; end; CDS_Outputdate.Value := qryStage.fieldbyname('outputdate').AsInteger; CDS_Outputshift.Value := qryStage

飞 艇 的 回 血 导 师 为 什 么 要 带 人

╄→гoц情女王★ 提交于 2019-12-01 20:31:35
【〓⑤⑦⑤⑥⑧③①②〓】邀请玛【①⑤⑧⑧①⑧⑧⑧】官网hct728点c0 m qryStage.First; //链接内部服务器SQL的query qryProductivity.First; //链接外部服务器SQL的query while not qryStage.Eof or qryProductivity.Eof do //此语句是否存在错误?我按照.net的思路来的 begin CDS_Output.Insert; CDS_Outputfac.Value := 'ZD00'; CDS_Outputres.Value := Copy(cbStage.Text,1,3); if not (cbShift.Text = '') then begin if StrToInt(cbStage.Text) in [010,020,030,060] then begin CDS_Outputarea.Value := 'DFZ-POWER-SMD'; end else begin CDS_Outputarea.Value := 'DFZ-POWER-SPI'; end; end; CDS_Outputdate.Value := qryStage.fieldbyname('outputdate').AsInteger; CDS_Outputshift.Value := qryStage