欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

hdu 2275 Kiki Little Kiki 1 水题

发布时间:2023/12/18 编程问答 40 豆豆
生活随笔 收集整理的这篇文章主要介绍了 hdu 2275 Kiki Little Kiki 1 水题 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2275

这个题比较简单,所以就没有测试样例提供给大家,基本把题目的样例过了就可以了

题目大意

给你一串操作,“Push  x”为添加元素x ;    

“Pop  x”为:在集合中找到一个不大于x的最大数,输出并删除,没有的话,输出“No Element!”

最后留一个空行

存储结构

multiset,一种允许有重复元素的set

思路

用set自带的upper_bound()函数找到大于x的位置,输出其前一个位置的元素值,如果不存在,那么一定返回一个begin()(意为全大于),判断即可

 

代码如下:

1 #include<iostream> 2 #include<set> 3 #include<string> 4 using namespace std; 5 6 int main() 7 { 8 int Group, number; 9 while (cin >> Group) 10 { 11 multiset<int> S; 12 string s; 13 while (Group--) 14 { 15 cin >> s >> number; 16 if (s == "Push") 17 S.insert(number); 18 else { 19 multiset<int>::iterator it = S.upper_bound(number); 20 if (it == S.begin()) 21 cout << "No Element!" << endl; 22 else { 23 cout << *(--it) << endl; 24 S.erase(it); 25 } 26 } 27 } 28 cout << endl; 29 } 30 }

谢谢您的阅读,生活愉快~

转载于:https://www.cnblogs.com/lv-anchoret/p/8371700.html

总结

以上是生活随笔为你收集整理的hdu 2275 Kiki Little Kiki 1 水题的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。