随笔分类 -  算法

摘要:void rotate(vector<int>& nums, int k) { int n = nums.size(); vector<int> newArr(n); for (int i = 0; i < n; ++i) { newArr[(i + k) % n] = nums[i]; } num 阅读全文
posted @ 2022-08-31 11:52 lwx_R 阅读(14) 评论(0) 推荐(0) 编辑
摘要:1.模板 求n的m次方 #include<iostream> #define MOD 1000000007 using namespace std; //递归快速幂 int quickpow(long long a,long long n){ if(n==0) return 1; else if(n 阅读全文
posted @ 2021-10-01 19:45 lwx_R 阅读(18) 评论(0) 推荐(0) 编辑
摘要:1.向上取整, ceil(x)返回的是大于x的最小整数。 2.向下取整, floor(x)返回的是小于或等于x的最大整数。 3.输出有效数字 若规定整数p位,小数部分q位 用%p.qf 输出 若规定整数+小数一共是n位有效 用%.ng 输出 4.c++域宽 setw() 阅读全文
posted @ 2021-10-01 19:35 lwx_R 阅读(44) 评论(0) 推荐(0) 编辑
摘要:1.recerse(v.begin(),v.end()) 反转容器元素顺序函数 2.sort(a,a+n,cmp); 自定义cmp函数 int cmp2(peo p1,peo p2){ if (change(p1.job)change(p2.job)){ if(p1.gradep2.grade) r 阅读全文
posted @ 2021-09-13 14:12 lwx_R 阅读(23) 评论(0) 推荐(0) 编辑
摘要:1.大小写改变 transform(s.begin(),s.end(),s.begin(),::tolower); 2.str2.find(str1,n) 从n位置开始在str2里找str1,成功返回找到的位置,否则返回-1 3.erase() 清除函数 str.erase("char c") 从s 阅读全文
posted @ 2021-09-13 14:03 lwx_R 阅读(22) 评论(0) 推荐(0) 编辑
摘要:1.strcpy(str1,str2) 将字符串str2复制到字符串str1中,并覆盖str1原始字符串,可以用来为字符串变量赋值 注意:1)字符串str2会覆盖str1中的全部字符,2)字符串str2的长度不能超过str1 2.strncpy(str1,str2,n) 将字符串str2中的前n个字 阅读全文
posted @ 2021-09-13 13:03 lwx_R 阅读(288) 评论(0) 推荐(0) 编辑
摘要:1.高精度加法(高精度加高精度) #include<iostream> #include<cstring> #define maxn 10000001 using namespace std; int a[maxn],b[maxn]; int c[maxn]; int lena,lenb; int 阅读全文
posted @ 2021-09-13 12:23 lwx_R 阅读(34) 评论(0) 推荐(0) 编辑
摘要:1.埃氏筛 /* *埃拉托斯特尼筛法 *1秒内找出1e6范围以内的全部素数 复杂度是O(nloglogn) *更高效的线性筛素数算法(欧拉筛法)。 */ void Era_prime(){ for(int i=2;i<maxn;i++){ if(!prime[i]){//prime数组筛选作用,不存 阅读全文
posted @ 2021-09-13 12:17 lwx_R 阅读(84) 评论(0) 推荐(0) 编辑
摘要:#include<iostream> #include<cstring> using namespace std; char c[105]; int lesschar(char*c,int p,int q){ int n=strlen(c); for(int i=0;i<n;i++){ cout<< 阅读全文
posted @ 2021-08-25 10:58 lwx_R 阅读(20) 评论(0) 推荐(0) 编辑
摘要:将键盘正确顺序放入数组,查找时i-1位即为正确位置 注意除了数组中输入和空格外 还有其他输入 `#include include using namespace std; int main() { char s[] = "`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZX 阅读全文
posted @ 2021-08-22 22:00 lwx_R 阅读(28) 评论(0) 推荐(0) 编辑
摘要:1.scanf() 速度比cin快,在输入大量数据时用scanf 2.scanf()遇到空格,回车会停止 getchar()则可以 循环读入数据 while((c=getchar())!=EOF) while(cin>>n&&n) 阅读全文
posted @ 2021-08-22 21:32 lwx_R 阅读(21) 评论(0) 推荐(0) 编辑
摘要:字符串输入输出 1.输入 char a[] scanf(%s,a)//空格停止 or scanf("%[^\n]",a); //可以读取空格,回车结束输入 gets()//回车停车 阅读全文
posted @ 2020-11-12 17:34 lwx_R 阅读(20) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示