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

相关推荐
Scott9999HH6 小时前
【IIoT流量实战】蒸汽管道阀门全关却仍有流量?用 Python 实现涡街信号 FFT 频谱分析与温压全补偿积算网关,深度拆解靠谱的涡街流量计厂家硬核技术标准
开发语言·python
2401_841495647 小时前
【操作系统】进程同步与互斥实验报告
c++·算法·操作系统·进程·并发·同步·互斥
fqbqrr7 小时前
2607C++,soui与安卓
c++·soui
码智社7 小时前
AES加密原理详解及Java实现加解密实战
java·开发语言
AI云海7 小时前
python 列表、元组、集合和字典
开发语言·python
萧瑟余晖8 小时前
JDK 26 新特性详解
java·开发语言
马优晨8 小时前
Freemarker 完整讲解(后端 Java 模板引擎)
java·开发语言·freemarker·freemarker 完整讲解·freemarker模板引擎
fqbqrr10 小时前
2607C++,使用微软detours勾挂工具
c++
人邮异步社区10 小时前
怎么把C语言学到精通?
c语言·开发语言
心平气和量大福大11 小时前
C#-WPF-控件-TextBox 数据绑定
开发语言·c#·wpf