C++

来源:互联网 发布:php 数组的写法 编辑:程序博客网 时间:2024/05/21 17:08

vector初始化二维数组

// 另一种二维数组初始化方法vector<vector<int>> mat(2,vector<int>(3,1));// 其中2表示行数,3表示每行有多少个,1表示每个单位储存的值  int a[][3] = {{1,2,3},{4,5,6},{7,8,9}};    vector<vector<int> > mat(3); // 定义这个有多少行    for (int i=0; i<3; i++) {        mat[i].resize(3); // 每一行的长度    }    for (int i=0; i<3; i++) {        for (int j=0; j<3; j++) {            mat[i][j] = a[i][j];        }    }    mat = rotateMatrix(mat, 3);

使用ceil函数。ceil(x)返回的是大于x的最小整数。
如: ceil(10.5) == 11 ceil(-10.5) ==-10

pow() 函数用来求 x 的 y 次幂(次方),其原型为:
double pow(double x, double y);

排序函数sort() 要导入

#include <algorithm>vector<int> Asort(A.begin(), A.end());

取出字符串中的单个字符,string A = “asd”
A[0] = a

取绝对值

abs()
0 0