import java.util.*;
class move {
int sno;
boolean movedierction;
int distance;
}
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();//学生数
int m = in.nextInt();//调整次数
move[] mo = new move[m];
for (int i = 0; i < m; i++) {
mo[i] = new move();
mo[i].sno = in.nextInt();
int a = in.nextInt();
if (a > 0) {
mo[i].movedierction = true;// 向右
mo[i].distance = a;
} else {
mo[i].movedierction = false;// 向左
mo[i].distance = -a;
}
}
int no = 1;
int[] stu = new int[n];
for (int k = 0; k < n; k++) {// 学号
stu[k] = no++;
}
for (int i = 0; i < m; i++) {
int temp = 0;// 该学生的下标
boolean flag = mo[i].movedierction;// 向右还是向左
for (int j = 0; j < n; j++) {
if (stu[j] == mo[i].sno)// 确定找到的数的下标
temp = j;
}
exchange(stu, mo[i].distance, temp, flag);//调整
}
for (int p = 0; p < n; p++) {//打印调整结束之后的结果
if (p == 0)
System.out.print(stu[p]);
else
System.out.print(" " + stu[p]);
}
}
public static void exchange(int[] stu, int dis, int temp, boolean flag) {
if (flag) {//向右
for (int j = dis; j > 0; j--) {
int v = stu[temp + 1];
stu[temp + 1] = stu[temp];
stu[temp] = v;
temp++;
}
} else {//向左
for (int j = dis; j > 0; j--) {
int v = stu[temp - 1];
stu[temp - 1] = stu[temp];
stu[temp] = v;
temp--;
}
}
}
}
CCF 学生排队 java
最新推荐文章于 2024-03-22 02:04:41 发布