新疆大学OJ(ACM) 1099: 数列有序!
生活随笔
收集整理的這篇文章主要介紹了
新疆大学OJ(ACM) 1099: 数列有序!
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1099: 數列有序!
時間限制: 1 Sec 內存限制: 128 MB
題目描述
有n(n<=100)個整數,已經按照從小到大順序排列好,現在另外給一個整數x,請將該數插入到序列中,并使新的序列仍然有序。
輸入
輸入數據包含多個測試實例,每組數據由兩行組成,第一行是n和m,第二行是已經有序的n個數的數列。n和m同時為0標示輸入數據的結束,本行不做處理。
輸出
對于每個測試實例,輸出插入新的元素后的數列。
樣例輸入
3 3
1 2 4
0 0
樣例輸出
1 2 3 4
代碼:
#include <iostream> #include <string.h> #include <string> #include <map> #include <algorithm> #include <set> using namespace std; typedef long long ll;multiset <int>::iterator it;int main() {int n,m;while(cin >> n >> m){if(n == 0&&m == 0) break;multiset <int> s;int key;while(n--) cin >> key,s.insert(key);s.insert(m);for(it = s.begin();it != s.end(); it++){if(it != s.begin()) cout << " ";cout << *it;}cout << endl;}return 0; } // written by zhangjiuding總結
以上是生活随笔為你收集整理的新疆大学OJ(ACM) 1099: 数列有序!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新疆大学OJ(ACM) 1047: st
- 下一篇: 【模板】堆的结构