/**
* 思路:在数组中寻找到跟p匹配的值,记录值跟下标
* 再遍历,对相应的值进行修改
*/
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
int[] nn = new int[n];
//location记录跟p匹配的值的位置
int p,q,location = 0;
//记录跟p匹配的值
int a = 0;
for (int i = 0; i < n; i++) {
nn[i] = i+1;
}
for (int i = 0; i < m; i++) {
p = scanner.nextInt();
q = scanner.nextInt();
for (int j = 0; j < n; j++) {
if (nn[j] == p){
location = j;
a = nn[j];
break;
}
}
if (q > 0) {
for (int j = location; j < location+q; j++) {
nn[j] = nn[j+1];
}
nn[location+q] = a;
}else {
for (int j = location; j > location+q; j--) {
nn[j] = nn[j-1];
}
nn[location+q] = a;
}
}
for (int b:nn
) {
System.out.print(b+"\t");
}
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交