STL知识点(3)

set相关操作:

#include <iostream>
#include <queue>
#include <cstring>
#include <set>

using namespace std;

class Student
{
	friend class Cmp;
	int id;
	char name[20];
public:
	Student(int i,char *n)
	{
		strcpy(name,n);
		id = i;
	}

	void print() const
	{
		cout << "id: " << id  << " name: " << name << endl;
	}

	bool operator < (const Student &s) const
	{
		return (this->id < s.id);
		//return (strcmp(s1.name,s2.name) <0);
	}

	bool operator > (const Student &s) const
	{
		return (this->id > s.id);
		//return (strcmp(s1.name,s2.name) <0);
	}
};

class Cmp
{
public:
	bool operator ()(const Student &s1,const Student &s2)
	{
		return (s1.id < s2.id);
		//return (strcmp(s1.name,s2.name) <0);
	}
};

int main()
{
	srand(time(NULL));
	set < Student,Cmp > s;
	
	Student s1(24,"aa");
	Student s2(25,"bb");
	Student s3(19,"cc");
	Student s4(18,"dd");
	Student s5(45,"ee");
	
	s.insert(s1);
	s.insert(s2);
	s.insert(s3);
	s.insert(s4);
	s.insert(s5);

	for(set<Student,Cmp>:: iterator it = s.begin(); it != s.end(); it++)
	{
		it->print();
	}
	cout << endl;

	if(s.empty())
	{
		cout << "set is empty" << endl;
	}
	else
	{
		cout << "size = " << s.size() << endl;
		cout << "set is not empty" << endl;
	}

	cout <<  "**************erase***************" << endl;

	set<Student,Cmp>:: iterator it = s.begin();
	it++;
	s.erase(it);
	for(it = s.begin(); it != s.end(); it++)
	{
		it->print();
	}
	cout << endl;

	Student cc(18,"cc");
	s.erase(cc);

	for(it = s.begin(); it != s.end(); it++)
	{
		it->print();
	}
	cout << endl;

	if(s.empty())
	{
		cout << "set is empty" << endl;
	}
	else
	{
		cout << "size = " << s.size() << endl;
		cout << "set is not empty" << endl;
	}
	
	cout << "***********find***************" << endl;
	
	Student aa(24,"bb");
	it = s.find(aa);
	if(it != s.end())
	{
		it->print();
	}
	else
	{
		cout << "don't find" << endl;
	}

	cout << "***********lower_bound***************" << endl;
	it = s.lower_bound(aa);
	if(it != s.end())
	{
		it->print();
	}
	else
	{
		cout << "don't find" << endl;
	}

	cout << "***********equal_range***************" << endl;
	pair< set<Student,Cmp>::iterator,set<Student,Cmp>::iterator > p;
	p = s.equal_range(aa);
	p.first->print();
	p.second->print();

	return 0;	
}

map相关操作:

#include <iostream>
#include <cstring>
#include <map>

using namespace std;

class Student
{
	
	int id;
	char name[20];
public:
	Student()
	{
	
	}
	Student(int i,char *n)
	{
		strcpy(name,n);
		id = i;
	}

	void print() const
	{
		cout << "id: " << id  << " name: " << name << endl;
	}
};


int main()
{		
	map<int,Student > m;
	
	Student s1(24,"aa");
	Student s2(25,"bb");
	Student s3(19,"cc");
	Student s4(18,"dd");
	Student s5(45,"ee");
	Student s6(34,"ff");
	Student s7(35,"gg");
	
	
	m.insert(pair<int ,Student>(1,s1));
	m.insert(pair<int ,Student>(2,s2));


	m.insert(make_pair(3,s3));
	m.insert(make_pair(4,s4));

	m.insert(map<int, Student>::value_type(5,s5));
	m.insert(map<int, Student>::value_type(6,s6));

	m[7] = s7;

	for(map<int,Student>::iterator it = m.begin();it != m.end(); it++)
	{
		cout << "id :" << it->first << endl;
		it->second.print();
	}

	pair<map<int, Student>::iterator,bool> p = m.insert(make_pair(3,s3));
	if(!p.second)
	{
		cout << "Insert Failure" << endl;
	}
	else
	{
		cout << "Insert Success" << endl;
	}

	cout << endl;

	
		return 0;	
}

multimap相关操作:

#include <iostream>
#include <cstring>
#include <map>

using namespace std;

class Empleyee
{
	
	int id;
	char name[20];
public:
	Empleyee()
	{
	
	}
	Empleyee(int i,char *n)
	{
		strcpy(name,n);
		id = i;
	}

	void print() const
	{
		cout << "id: " << id  << " name: " << name << endl;
	}
};


int main()
{		
	multimap<string,Empleyee > m;
	
	Empleyee e1(24,"aa");
	Empleyee e2(25,"bb");
	Empleyee e3(19,"cc");
	Empleyee e4(18,"dd");
	Empleyee e5(45,"ee");
	Empleyee e6(34,"ff");
	Empleyee e7(35,"gg");

	m.insert(make_pair("sale",e1));
	m.insert(make_pair("sale",e2));
	m.insert(make_pair("sale",e3));

	m.insert(make_pair("develop",e4));
	m.insert(make_pair("develop",e5));
	m.insert(make_pair("develop",e6));

	m.insert(make_pair("financial",e7));
	m.insert(make_pair("financial",e4));

	int num = m.count("develop");
	cout << "develop:" << num << endl;
	

	multimap<string,Empleyee>::iterator it = m.find("develop");
	for(int i = 0;i < num;i++)
	{
		it->second.print();
		it++;
	}


	cout << endl;

	
		return 0;	
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 蜘蛛侠3D打印模型STL文件是一种用于打印蜘蛛侠立体模型的文件格式。STL(Standard Tessellation Language)是一种常见的三维模型文件格式,它将模型分割成无数个小三角形,以便于计算机识别和打印。 使用蜘蛛侠3D打印模型STL文件,您可以在3D打印机上打印出一个逼真的蜘蛛侠模型。这个模型将由细小的塑料线层层堆积而成,最终呈现出一个立体的、可以放在手中观察的蜘蛛侠形象。 在使用STL文件之前,您需要先将文件加载到3D打印机或打印软件中。然后,您可以根据需要进行调整,例如改变模型的大小、旋转角度或者修改细节部分。一旦准备好,您可以选择适合的打印设置,如打印速度和打印材料,然后开始打印。 3D打印机会根据STL文件中的数据,一层一层地将塑料材料加热并堆积,逐渐形成完整的蜘蛛侠模型。整个过程可能需要几个小时,具体时间取决于模型的复杂程度和打印机的速度。 完成打印后,您可以小心地取出打印好的蜘蛛侠模型,去掉支撑结构,然后您就可以欣赏到一个精美的、逼真的蜘蛛侠模型了。这个模型可以用作装饰品、礼物或者收藏品,也可以用来展示您的3D打印技术。 总而言之,蜘蛛侠3D打印模型STL文件让您能够在3D打印机上创建一个逼真的蜘蛛侠模型,从而体验到3D打印技术的乐趣和魅力。 ### 回答2: 蜘蛛侠是一个备受喜爱的超级英雄角色,拥有超凡的能力和独特的装备。由于其广泛的影响力和强大的粉丝群,很多人都想拥有一个蜘蛛侠的3D打印模型。 要制作一个蜘蛛侠的3D打印模型,首先需要一个STL文件。STL是一种常用的3D模型文件格式,它包含了模型的几何信息,例如点、线和面的坐标。 为了制作蜘蛛侠的3D模型,首先需要一个蜘蛛侠的设计图。这个设计图可以通过手绘、计算机绘图软件或者从相关的游戏、电影中截取图像而得到。然后,需要将设计图转换成3D模型。可以使用CAD软件(计算机辅助设计)来完成这个转换过程。 一旦完成了3D模型的设计,就可以导出成为STL文件。导出STL文件的过程中,需要将模型进行三角化,将连续的曲面分割成很多小的三角形面片。这是因为3D打印机只能打印出一层一层的平面,无法处理连续的曲面。 有了STL文件后,就可以使用3D打印机来打印蜘蛛侠的模型了。首先需要准备打印材料,例如ABS或者PLA。然后,将STL文件导入到3D打印机的软件中,并进行一些设置,例如打印分辨率、打印速度等。最后,启动打印机,等待打印完成。 当3D打印机完成打印后,就可以得到一个蜘蛛侠的3D打印模型了。模型的质量和细节取决于设计和打印的精度。可以选择使用喷漆或者其他的装饰来润色和个性化模型。 总之,制作一个蜘蛛侠的3D打印模型需要设计图、CAD软件、3D打印机和STL文件等工具和材料。通过合理的设计和精细的打印,可以制作出一个栩栩如生的蜘蛛侠模型,让人们可以更加真实地感受和欣赏这位超级英雄的魅力。 ### 回答3: 蜘蛛侠3D打印模型STL是一种3D模型文件格式,用于创建蜘蛛侠的立体打印模型。STL文件是一种常用的三维模型交换格式,可以被众多3D打印机所识别和使用。 要创建一个蜘蛛侠3D打印模型,首先需要找到或设计一个合适的3D模型文件。这个文件可以通过多种方法获取,例如从网上下载已经存在的蜘蛛侠3D模型,或者使用专业的3D建模软件制作自定义的蜘蛛侠模型。 一旦获取或设计了合适的3D模型文件,需要使用一个支持STL格式的3D打印机或者软件来进行打印。将STL文件导入3D打印机或软件中,并进行一些参数设置,例如打印质量、打印速度等。 然后,选择适合的3D打印材料,例如PLA、ABS等,并准备好打印所需的材料和耗材。将打印机预热至所需温度,然后启动打印过程。 打印时间和质量取决于所选的打印参数和材料。一旦打印完成,将蜘蛛侠3D模型从打印平台上取出,并进行一些必要的后处理工作,例如修剪、抛光等,以获得更好的效果。 蜘蛛侠3D打印模型STL的制作过程需要一定的技术和专业知识,通常需要有一定的3D建模和打印经验。这种模型的制作可以满足蜘蛛侠迷的收藏需求,也可以作为一种创意礼物或者装饰品。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值