C++ 代码实现:旅游团身高排序 - 将最高游客置于最前
#include\x20
int\x20main()\x20{\x20\x20\x20int\x20n;
\x20\x20\x20cin\x20>>\x20n;
\x20\x20\x20vector
\x20\x20\x20for\x20(int\x20i\x20=\x200; i\x20<\x20n; i++)\x20{
\x20\x20\x20\x20\x20\x20cin\x20>>\x20heights[i];
\x20\x20\x20}\x20\x20\x20int\x20maxIndex\x20=\x20max_element(heights.begin(), heights.end())\x20-\x20heights.begin();
\x20\x20\x20swap(heights[0], heights[maxIndex]);
\x20\x20\x20for\x20(int\x20i\x20=\x200; i\x20<\x20n; i++)\x20{
\x20\x20\x20\x20\x20\x20cout\x20<<\x20heights[i]\x20<<\x20"\x20";
\x20\x20\x20}\x20\x20\x20return\x200;
}
原文地址: https://www.cveoy.top/t/topic/qlz4 著作权归作者所有。请勿转载和采集!