2025四月刷题记录
做着玩
一、语法学习
- 逻辑:与
&&
,或||
,非!
,异或^
P5710【深基3.例2】数的性质 https://www.luogu.com.cn/problem/P5710
二、库学习
1、标准库
static_cast<char>(...)
显式类型转换,用于将表达式的结果转换为 char 类型
num.begin()
和 num.end()
用于获取指向容器起始位置和结束位置的迭代器
2、iomanip
I/O manipulator
(1) 输出精度控制
cout<<fixed<<setprecision(1)<<S<<endl;
fixed代表转化为小数点表示法(不然是科学计数法),然后set precision设置精度(全局)
P5706再分肥宅水 https://www.luogu.com.cn/problem/P5706
P5708三角形面积 https://www.luogu.com.cn/problem/P5708
P5714【深基3.例7】肥胖问题 https://www.luogu.com.cn/problem/P5714
(2) 时间占位
cout << setfill('0') << setw(2) << h << ":" << setw(2) << m << endl;
setfill设置占位字符,set w设置占位宽度(大于宽度不会限制,直接输出)
- setfill 是持久的(全局的),它会一直生效,直到被另一个 setfill 调用改变。
- setw 是一次性的,它只影响紧随其后的下一个输出项。
P5707上学迟到 https://www.luogu.com.cn/problem/P5707
3、algorithm
(1) 字符串反转
reverse(num.begin(), num.end());
reverse() 用于反转容器中元素的顺序
P5705数字反转 https://www.luogu.com.cn/problem/P5705
4、cctype
C character type
(1) 大小写转换
cout<< static_cast<char>(tolower(a))<<endl;
cout<< static_cast<char>(toupper(a))<<endl;
P5704字母转换 https://www.luogu.com.cn/problem/P5704
5、cstdio
(1) 字符串匹配
scanf("%c%c%c.%c",&a,&b,&c,&d);
printf("%c.%c%c%c",d,c,b,a);
中间有个小数点刚好可以匹配123.4的.
P5705数字反转 https://www.luogu.com.cn/problem/P5705
6、cmath
向上取整:ceil()
,向下取整:floor()
P5709【深基2.习6】苹果和虫子 https://www.luogu.com.cn/problem/P5709
开根号:sqrt()
,开立方:cbrt()
P2433【深基1-2】小学数学N合一 https://www.luogu.com.cn/problem/P2433