&&与||小提示
&&&&运算符从左自由依次判断 ,如果判断有一个为假则停止判断
||同理如果判断有一个为真则停止判断
例#include<iostream>
using namespace std;
int main()
{
int a=0,b=1,c;
c = (a != b) || (++a == b++);
cout<<a<<" "<<b<<endl;
return 0;
}
输出为0 1因为前面一个为真,直接退出判断
“凸包”
凸包就是把平面中所有点都包进去的凸多边形,当然多边形上的点也是题目中给出的点
分治法 1 首先,横坐标最小p1和最大pn的点一定是凸包上的点 2上包,即离p1pn最远的点,记pmax 3再把pmax与p1连接,求左侧的上包,重复上述过程即可求解
string大小写字母转换
在algorithm库中有transform函数transform(str.begin(),str.end(),str.begin(),::toupper)注意transform有四个输入参数1:str.begin()字符串的起始地址;2:str.end()字符串的终止地址;3:str.begin()是转换之后,输出到原str字符串的起始地址;4:转换操作,可以选择toupper,tolower。
vector
vector的定义vector<数据类型> 标识符
vector的函数begin()返回开头元素的迭代器
end()同理
front() 返回开头元素的引用
back() 返回末尾元素的引用
size()返回vector内元素的数量
erase(迭代器) 删除一个元素
clear() 清空
insert(迭代器,a) 把a插入迭代器后
例vector中现在有1 2 3 三个元素,vec.insert(vec.begin()+2,4)得到1 2 4 3
算法reverse(vec.begin(),vec.end()) (头文件<algorithm>)
实际上不一定是begin到end,也可以begin()+1到、、、,只需要用迭代器就行了
sort排序,也要用<algorithm>默认升序bool Comp(const int &a,const int &b){ return a>b;}调用时:sort(vec.begin(),vec.end(),Comp),这样就降序排序。
二维数组vector< ...
unix文件系统
文件就是任意源,有一个名称,可以从中写入读出数据。
文件类型unix中有三种文件类型,普通文件,目录和伪文件。
普通文件是大多数时候所使用的文件,包括文本文件和二进制文件。例如,纯文本,shell脚本,源程序,配置文件,html文件等。
目录不同之处在于他们用来组织,访问其他文件。从概念上讲,目录包含其他文件。这个文件其实类似于windows下的文件夹。
伪文件有时候也称为设备文件。这种文件是物理设备的内部表示。例如键盘,显示器,打印机等,这些设备都可以当成一个文件进行访问。
有一种特殊的伪文件时proc文件,这种文件可以访问linux内核中的信息,设置可以修改Linux内核中的数据。
特殊文件特殊文件就是表示物理设备的伪文件。这些文件都被存放于/dev下
一些常见的设备如下
位置
硬件
/dev/sda
SCSI硬盘
/dev/sda
第一分区
/dev/hda
硬盘
/dev/Ip0
打印机
/dev/tty
当前终端
/dev/random
随机数生成器
/dev/null
放弃输入 输入不返回内容
/dev/zero
放弃送站,输入返 ...
set
set之iterator定义:set::iterator iter
运用:*iter
遍历 for(iter=set.begin();iter!=set.end();iter++)
还可以直接用auto it=set.begin() (auto是自动匹配类型)
注意iterator只能用++,–运算符。不能*(iter-1),另外还要注意iter++后自身会改变
例:set中有0,2,4,iter指向2,现在cout<<iter<<” “<<(iter—)<<endl;
输出0,2,先执行iter–,我也不知道为什么
set之lower_bound()lower_bound()返回从first开始的第一个大于或等于val的元素的地址。如果所有元素都小于val,则返回last的地址,所以必须要set<int>::iterator iter;iter=st.lower_bound(一个数字)
upper_bound()返回最后一个大于等于val的元素的地址
set基础定义:set<数据类型> 标识符 ,set中元素都唯 ...
unix基础
操作系统有初始化功能,初始化过程只是引导过程的一部分
引导过程是计算机启动时会运行一个小程序,然后再运行另一个程序,逐层运行,最后运行一个十分复杂的程序,这个程序名字是内核。
内核是操作系统的核心,因此只要计算机开启,内核边一直运行。
内核可以分为微内核和单内核两种。单内核较大,运行速度较快,但是由于没有采用模块化设计,维护修改比较困难。而微内核自己只能运行最基本的功能,其他功能要交给服务器去运行(微内核调用的其他程序),微内核速度慢,但适用于定制化的任务,如移动电话。
unix=内核+使用工具只有内核并不能带来很好的用户体验,因此还有许多其他的程序。最重要的是为用户提供计算机界面的程序,shell 和 GUI。
shell 是一种提供基于文本的界面的程序,也就是平时所说的命令提示符。
而 GUI(graphical user interface)是使用窗口,鼠标指针,图标等提供图形界面.
这些工具称为Unix实用工具,有几百个。
服务器和客户端早期由于主机昂贵而终端便宜,所以经常是多个主机连接一个终端。因此服务器和客户端的概念也因此产生。
提供某种类型的服务的程序叫做服务器,使用 ...
si和di
si和di在8086cpu中的功能与bx类似,si与di不能分为两个8位寄存器来使用
也就是说 ds:[si]是可以的
如果不用这些寄存器直接写的话就会出现之前所说的编译器和exe对程序的不同处理
例 mov ax,[si]在exe中就是 ds:[si],但是如果是 mov,ax,[1]在exe中就是把ax中的数据放入1中
甚至可以直接用[bx+si]的方式或[bx+si+idata]的方式来指明内存地址
不同寻址方式的比较[idata]用于一个常量的寻址,直接定位一个内存单元
[bx]用于一个变量来表示内存地址,间接定位内存单元
只有bx,bp,di,si具有寻址能力,例如ds:[dx]等都是错误的
并且这几个寄存器间组合还有要求,只有bx+si,bx+di,bp+si,bp+di这四种情况是正确的
只要使用bp,它的段寄存器默认为ss
scanf printf
scanf格式:scanf(const char *format, …)
format — 这是 C 字符串,包含了以下各项中的一个或多个:空格字符、非空格字符 和 format 说明符。
format 说明符形式为:
[=%[*][width][modifiers]type=]
*这是一个可选的星号,表示数据是从流 stream 中读取的,但是可以被忽视,即它不存储在对应的参数中。
width 这指定了在当前读取操作中读取的最大字符数。
modifiers 为对应的附加参数所指向的数据指定一个不同于整型(针对 d、i 和 n)、无符号整型(针对 o、u 和 x)或浮点型(针对 e、f 和 g)的大小: h :短整型(针对 d、i 和 n),或无符号短整型(针对 o、u 和 x) l :长整型(针对 d、i 和 n),或无符号长整型(针对 o、u 和 x),或双精度型(针对 e、f 和 g) L :长双精度型(针对 e、f 和 g)
type 一个字符,指定了要被读取的数据类型以及数据读取方式。具体参见下一个表格
符号
作用
具体含义
%a、%A
读入 ...
union
首先看一下结构体,c语言中的结构体占用字节数是所有类型字节数的总和。
例如:struct node{ int a; int b;}用sizeof测试一下结果是8,但是如果用union呢?会发现结果是4
union中的参数共用同一块内存空间,它们在内存中起始地址都相同,也就是说同一时间内联合体中其实只会有一个参数存在,当另一个参数被赋值时,此时内存中存的就是另一个参数的值,而前面的参数会被覆盖
但是size并不一定是根据最长的那个长度来决定的(实测不是,但是不懂),还要考虑内存对齐的问题
如果此时已经给某一变量赋上了值,再用另外一个变量输出,那么内存中的编码并不会改变,只是会按找相应类型的编码方式进行编码然后输出。
在c++中的使用
大致相同,但是union中不能有类,如果我们在再类CA中添加了构造函数,或者添加析构函数,我们就会发现程序就会出现错误。由于union里面的东西共享内存,所以不能定义静态、引用类型的变量。由于在union里也不允许存放带有构造函数、析构函数和复制构造函数等的类的对象,但是可以存放对应的类对象指针
应用 类型转换
因为u ...