1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00
2021-06-29 14:52:42 +08:00

67 lines
1.4 KiB
Plaintext

snippet bare "barebone code template"
#include <iostream>
#include <vector>
#include <string>
using std::cout;
using std::endl;
using std::vector;
using std::string;
int main()
{
return 0;
}
endsnippet
snippet icd "#include directive" b
#include <$1>
$0
endsnippet
snippet plist "print vector" w
void printList(vector<int>& arr, const string& desc){
cout << desc << ": ";
for (auto it = arr.begin(); it != arr.end(); it++){
cout << *it << ((it != arr.end()-1) ? ' ' : '\n');
}
}
endsnippet
snippet pmat "print list of list" w
void printMat(const vector<vector<int>>& mat, const string& desc){
cout << desc << ": " << endl;
for (auto it1 = mat.begin(); it1 != mat.end(); it1++){
auto cur_vec = *it1;
for (auto it2 = cur_vec.begin(); it2 != cur_vec.end(); it2++){
cout << *it2 << ((it2 != cur_vec.end()-1) ? ' ' : '\n');
}
}
}
endsnippet
snippet cout "print a variable" w
cout << "$1: " << $2 << endl;
endsnippet
snippet random "Generate a random list" b
// Generate a random sequence of length len, in range(low, high) (inclusive).
// need to #include<random>
vector<int> genRandom(int low, int high, int len){
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> distribution(low, high);
vector<int> arr(len, 0);
for (int i = 0; i != len; ++i){
arr[i] = distribution(gen);
}
return arr;
}
endsnippet