酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

用c++写, 题目描述:要求输入一个柱面访问请求序列以及当前磁头所在柱面号和移动方向,输出采用电梯调度算法时移动臂响应的柱面访问序列。 输入格式:程序要求输入3行,以回车符号作为分隔,第一行是2个整型数n,m,之间用空格隔开,n表示当前磁头所在柱面号,m表示第二行输入m个数;第二行是m个整数,数之间以空格作为分隔,表示柱面访问请求序列,第三行是数字-1或者1,当为-1时表示移动臂向柱面号减小方向移动,当为1时,表示移动臂向柱面号增大方向移动。 输出格式:使输出m个整数,数之间以空格作为分隔,采用电梯调度算法时移动臂响应的柱面访问序列 在黑框中输入 15 10 24 38 2 110 43 36 5 11 6 180 -1 enter输出 11 6 5 2 24 36 38 43 110 180

#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int current_cylinder, num_requests, direction; cin >> current_cylinder >> num_requests; vector<int> requests(num_requests); for(int i = 0; i < num_requests; i++) { cin >> requests[i]; } cin >> direction; if(direction == -1) { sort(requests.begin(), requests.end(), greater<int>()); } else { sort(requests.begin(), requests.end()); } for(int i = 0; i < num_requests; i++) { cout << requests[i] << " "; } return 0; } [2024-11-07 17:06:08 | AI写代码神器 | 401点数解答]

相关提问