// Online C++ compiler to run C++ program online
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<iomanip>
#include<string.h>
#include<exception>
#include<map>
#include<cmath>
#include<unordered_map>
#include<set>
#include<climits>
#include<ctype.h>
#include<queue>
#include<string>
using namespace std;
struct Item
{
int prio;
int idx;
};
int main() {
string str;
// 带空格的字符串输入
getline(cin, str);
//逗号分割
vector<Item> list;
str += ",";
int id = 0;
while (str.find(",") != string::npos) {
int idx = str.find(",");
string t = str.substr(0, idx);
str = str.substr(idx + 1);
list.push_back({ atoi(t.c_str()), id++ });
}
vector<Item> outList;
while (list.size()) {
int prio = list[0].prio;
if (list.size() == 1)
{
outList.push_back(list[0]);
list.clear();
break;
}
bool find = false;
for (auto it = list.begin() + 1; it != list.end(); ++it)
{
if (it->prio > prio)
{
find = true;
break;
}
}
if (find)
{
list.push_back(*list.begin());
list.erase(list.begin());
continue;
}
outList.push_back(list[0]);
list.erase(list.begin());
}
for (int i = 0; i < outList.size(); ++i) {
cout << outList[i].idx;
if (i != outList.size() - 1) {
cout << ",";
}
}
return 0;
}
华为OD机试-打印任务排序
最新推荐文章于 2024-05-25 01:38:23 发布