C++ Grammar Study Summary (1)

bool 1byte

char 1byte

Int 4byte -21477483648~2147483648

Float 4byte

Double 8byet 15~16位

Long long 8byte -263~263

Long double 12~16byte 18~19位

1 byte = 4 bytes

   int %d

   float %f

   double: %lf

   char :%c

   long long: %lld 

Initialize the array #include memset(m,a,b);

                  M表示数组  赋值a  到b结束  (a,b都以byte位单位) 

Copy array void *memcpy(void *destin, void *source, unsigned n);

       destin-- 指向用于存储复制内容的目标数组,类型强制转换为 void* 指针。

       source-- 指向要复制的数据源,类型强制转换为 void* 指针。

       n-- 要被复制的字节数。

   例:memcpy(b,a,siceof a);

Calculate the m power of n#include pow(n,m)

String

string.pop_back delete the last character of the string

读入包含空格的字符串用

								fgets(名称,数量,stdin)  会将回车读入

								getline(cin,字符串)

Strings can connect characters through + operation

substr (start index, number)

strcmp(str1,str2) is used to compare two strings and returns an integer based on the comparison result.

Cin does not read spaces, cout can output spaces

stringstream ssin(string) reads the string in a stream, so that == "can directly extract the required information from the string<

Time function int clock();

string.back() returns the last character of the string

string.pop_back removes the last character of the string

swap(a,b) swap the values ​​of a and b (any type)

The first type of double pointer algorithm

Two pointers are used to find the number of consecutive identical elements

for(int i = 0;i<size;i++){ //i is the initial pointer, pointing to the beginning

int j = 1;	//j为工具指针,判断当前元素是否和s[i]相等

while(i<size&&s[i] == s[j]) 	j++;	//如果j所指元素与当前元素相等,则继续向前比较。

i = j-1; 	

}

Guess you like

Origin blog.csdn.net/weixin_44192389/article/details/109298032