概述
vector
给你一些图书馆进出人员列表,每个人有不同数字编号。。问图书馆的最小容纳人数。。。
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
vector<int> L;
int main()
{
int n;
L.clear();
scanf("%d",&n);
int out=0;
while(n--)
{
getchar();
int x;
char c;
scanf("%c %d",&c,&x);
vector<int>::iterator result=find(L.begin(),L.end(),x); //查找x
if (result==L.end()&&c=='+')
//没找到
{
L.push_back(x);
int a=L.size();
out=max(out,a);
}
else if(result==L.end()&&c=='-')
{
out++;
}
else if(result!=L.end()&&c=='-')//找到了
{
L.erase(result);
}
// else if(result!=L.end()&&c=='+') //不存在
}
printf("%dn",out);
return 0;
}
排列
直接用c++中的next_permutation 表示产生下一个全排列。
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int len;
char a[250];
while(gets(a))
{
len=strlen(a);
sort(a,a+len);
printf("%sn",a);
while(next_permutation(a,a+len))
{
printf("%sn",a);
}
}
return 0;
}
最后
以上就是雪白雨为你收集整理的算法笔记--c++STL的全部内容,希望文章能够帮你解决算法笔记--c++STL所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复