C++课后习题训练记录Day50

1.练习项目:

练习使用set函数及其常用函数

2.选择课程

在蓝桥云课中选择课程《16届蓝桥杯省赛无忧班(C&C++ 组)4期》,选择第STL"课程15并开始练习。

3.开始练习

(1)源码:

#include<bits/stdc++.h>

using namespace std;

int main()

{

ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

set<int>myset;

myset.insert(5);

myset.insert(2);

myset.insert(8);

myset.insert(2);

cout<<"set elements: ";

for(const auto&elem:myset){

cout<<elem<<" ";

}

cout<<endl;

int searchelement=5;

auto it=myset.find(searchelement);

if(it!=myset.end()){

cout<<searchelement<<" found in this set"<<endl;

}else{

cout<<searchelement<<" not found in this set"<<endl;

}

int removeelement=2;

myset.erase(removeelement);

for(const auto&elem:myset){

cout<<elem<<" ";

}

cout<<endl;

myset.clear();

if(myset.empty()){

cout<<"set is empty"<<endl;

}else{

cout<<"set is not empty"<<endl;

}

return 0;

}

(2)检验结果

对此代码进行检验,检验后无报错,提交此代码,判题结果为正确100分。

(3)练习心得:注意每段代码末尾的分号是否存在,如不存在则需即使补充;输入法是否切换为英语模式;语法是否错误。

相关推荐
yiangL_3 小时前
课后作业4:基于 Python 的古诗词词云可视化(P205)
开发语言·python
JosieBook4 小时前
【鸿蒙开源】把 Windows 任务栏上的流量表搬到鸿蒙 PC:TrafficMonitor 1.86 的 C++ 内核移植实践
c++·windows·harmonyos
Huangjin007_5 小时前
【C++ 算法竞赛篇】STL 常用知识点速通指南
c++·算法
geovindu5 小时前
rust: Functional Options Pattern
开发语言·后端·设计模式·rust·函数式选项模式·惯用法型模式
skywalk81636 小时前
把「假成功」赶出工具层:lightharness 两天升级复盘(4×5 模式矩阵 + 工具层 5 个缺陷)
开发语言·前端·人工智能·lightharness
敲上瘾6 小时前
Qt控件通用属性:geometry、qrc资源到QSS样式表等
开发语言·c++·qt·ui
炸膛坦客7 小时前
单片机/C/C++八股:(三十三)取别名
c语言·c++·单片机
听情歌落俗7 小时前
嵌入式学习1-C语言基础语法与STM32实践
c语言·开发语言
小飞在努力8 小时前
【实现负载均匀在线判题⑤】MVC 架构搭建与 Model 题目数据模块实现
c语言·开发语言·c++·笔记·后端
ShineWinsu8 小时前
对于Qt:QFontDialog的解析
c++·qt·面试·gui·字体·客户端·qfontdialog