随笔分类 -  编程基础问题

保留小数,有效位数
摘要:#include<iostream> #include<cstring> #include<iomanip> using namespace std; int main() { double ce=1.2323; cout<<setprecision(4)<<ce<<endl;//1.232 cou 阅读全文
posted @ 2023-01-28 10:53 ruoye123456 阅读(16) 评论(0) 推荐(0) 编辑
康托展开和康托逆展开
摘要:#include<bits/stdc++.h> using namespace std; int f[20]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); f[0]=1; for(int i=1;i<=10;++ 阅读全文
posted @ 2023-01-27 11:32 ruoye123456 阅读(15) 评论(0) 推荐(0) 编辑
输入问题
摘要:#include<bits/stdc++.h> using namespace std; int main() { int m,n; scanf("%d: (%d)",&m,&n);//输入1: (3) cout<<m<<' '<<n;//输出1 3 return 0; } #include<bit 阅读全文
posted @ 2023-01-23 11:06 ruoye123456 阅读(20) 评论(0) 推荐(0) 编辑
常用库函数
摘要:1.reverse和unique #include<algorithm> #include<iostream> #include<vector> using namespace std; int main() { vector<int> v({1,2,3,4,5,5}); reverse(v.beg 阅读全文
posted @ 2023-01-09 12:36 ruoye123456 阅读(31) 评论(0) 推荐(0) 编辑
简单位运算
摘要:#include<iostream> int main() { int a=1; int b=8; std::cout<<(~a)<<'\n'; std::cout<<(a<<1)<<'\n'; std::cout<<(a<<1|1)<<'\n'; std::cout<<(b>>3&1)<<'\n' 阅读全文
posted @ 2023-01-08 21:56 ruoye123456 阅读(21) 评论(0) 推荐(0) 编辑
继承的题目
摘要:题目描述 定义一个学生基类Student,包括私有数据成员:学校名、姓名、年龄,输出数据成员值的公有成员函数Print()。再定义一个研究生类G_Student,公有继承方式派生于学生类Student,其中新增私有数据成员:导师姓名,并定义输出研究生数据的公有成员函数Print()。实现学生信息的输 阅读全文
posted @ 2022-12-25 22:57 ruoye123456 阅读(30) 评论(0) 推荐(0) 编辑
字符变量写入二进制码
摘要:#include<iostream> int main() { char c1='\376';//-2 //写进去的是11111110 unsigned char c2='\376';//254 short i1=c1,i2=c2; std::cout<<i1<<" "<<i2<<std::endl 阅读全文
posted @ 2022-12-16 12:10 ruoye123456 阅读(15) 评论(0) 推荐(0) 编辑
构造和析构
摘要:题目内容: 设计学生类,数据成员包括学号、姓名、年龄、成绩;成员函数有构造函数、析构函数。定义带默认参数值的构造函数,默认值为:2021001,“Lili”,19,89.5。定义析构函数,析构时输出:学号,姓名,以及提示字符串“~~~”。编写主程序测试代码,定义一个不带参数的对象,读取用户输入信息作 阅读全文
posted @ 2022-12-12 23:26 ruoye123456 阅读(61) 评论(0) 推荐(0) 编辑
加速小技巧
摘要:#include<iostream> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);//关闭流同步后cin与scanf接近 //浮点数cin会慢 int a,b; cin>> 阅读全文
posted @ 2022-12-09 15:44 ruoye123456 阅读(19) 评论(0) 推荐(0) 编辑
类和对象
摘要:time.h #include<iostream> using namespace std; class Time { private: int hour; int minute; int second; public: void showtime(); Time(int h = 0, int m 阅读全文
posted @ 2022-12-09 00:44 ruoye123456 阅读(17) 评论(0) 推荐(0) 编辑
vs取消scanf的warning
摘要:#define _CRT_SECURE_NO_WARNINGS 阅读全文
posted @ 2022-12-08 21:53 ruoye123456 阅读(40) 评论(0) 推荐(0) 编辑
char数组转int后的指针显示值
摘要:#include"iostream" using namespace std; int main(void) { char str[]="1234567890"; int*p=(int*)str; printf("%x\n",*(p+1));//0x38373635 cout<<*(p+1)<<en 阅读全文
posted @ 2022-12-02 23:24 ruoye123456 阅读(25) 评论(0) 推荐(0) 编辑
int *p[]的一些使用
摘要:int *p[]是一个存数组的指针,其中的元素是指针,要对元素所指的位置调用需要二阶调用 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int a[10][6], * p 阅读全文
posted @ 2022-12-02 08:44 ruoye123456 阅读(317) 评论(0) 推荐(0) 编辑
指针实现字符串排序
摘要:题目描述 在主函数中输入5个字符串(每个字符串的长度不大于20),并输出这5个字符串。编写一个排序函数,完成对这些字符串按照字典顺序排序。然后在主函数中调用该排序函数,并输出这5个已排好序的字符串。要求用指针数组处理这些字符串。 样例输入 c****** a****** e****** g***** 阅读全文
posted @ 2022-12-01 23:39 ruoye123456 阅读(286) 评论(0) 推荐(0) 编辑