// 贴上第二个代码,只通过了60% #include <iostream> #include <vector> #include <algorithm> struct X { int priority; int order; X(int p, int o) : priority(p), order(o) {} friend bool operator<(const X& lhs, const X& rhs); }; bool operator<(const X& lhs, const X& rhs) { return lhs.priority > rhs.priority; } void printOrder(const int input[], int len, int output[]) { if (len == 0) return; std::vector<X> xs; xs.reserve(len); for (int i = 0; i < len; ++i) { xs.emplace_back(input[i], i); } std::stable_sort(xs.begin(), xs.end()); for (int i = 0; i < len; ++i) { output[i] = xs[i].order; } } int main() { char in; std::vector<int> temp; while (std::cin >> in) { if (in == ',') continue; temp.push_back(in - '0'); } int *input = new int[temp.size()]; int *output = new int[temp.size()]; int len = temp.size(); for (int i = 0; i < len; ++i) *(input + i) = temp[i]; printOrder(input, len, output); for (int i = 0; i < len; ++i) { if (i == 0) std::cout << output[i]; else std::cout << ", " << output[i]; } }
点赞 评论

相关推荐

点赞 评论 收藏
分享
牛客网
牛客企业服务