hdu 2275 Kiki Little Kiki 1 水题
生活随笔
收集整理的這篇文章主要介紹了
hdu 2275 Kiki Little Kiki 1 水题
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
題目:http://acm.hdu.edu.cn/showproblem.php?pid=2275
這個題比較簡單,所以就沒有測試樣例提供給大家,基本把題目的樣例過了就可以了
題目大意
給你一串操作,“Push ?x”為添加元素x ; ? ?
“Pop ?x”為:在集合中找到一個不大于x的最大數(shù),輸出并刪除,沒有的話,輸出“No Element!”
最后留一個空行
存儲結(jié)構(gòu)
multiset,一種允許有重復元素的set
思路
用set自帶的upper_bound()函數(shù)找到大于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 }謝謝您的閱讀,生活愉快~
轉(zhuǎn)載于:https://www.cnblogs.com/lv-anchoret/p/8371700.html
總結(jié)
以上是生活随笔為你收集整理的hdu 2275 Kiki Little Kiki 1 水题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MAC OSX在视图port哪个程序占用
- 下一篇: 今天升级win10.vs调试程序各种崩溃