zoukankan      html  css  js  c++  java
  • 201703-2 学生排队 Java

    思路:
    将需要移动的学生remove后再add
    题目中说向前向后移动不会超过人数,也就是不会出现隔着的情况。所以不会越界。

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n = Integer.parseInt(sc.nextLine());
    		int m = Integer.parseInt(sc.nextLine());
    		List<Integer> numbers = new ArrayList<>();
    		for(int i=1;i<=n;i++) {
    			numbers.add(i);
    		}
    		for(int j=0;j<m;j++) {
    			String [] line = sc.nextLine().split(" ");
    			Integer sno = Integer.parseInt(line[0]);//学号
    			int move = Integer.parseInt(line[1]);//移动
    			int index = numbers.indexOf(sno) + move;
    			numbers.remove(sno);
    			numbers.add(index, sno);
    		}
    		sc.close();
    		for(int k=0;k<n;k++) {
    			System.out.print(numbers.get(k) + " ");
    		}
    	}
    
    }
    
  • 相关阅读:
    盛大自动化运维
    Redis used_cpu_sys used_cpu_user meaning (redis info中cpu信息的含义)
    redis info 详解
    htop详解
    线程问题排查思路
    网络协议基础 -- 东哥
    线程通讯
    进程
    day14
    day13
  • 原文地址:https://www.cnblogs.com/yu-jiawei/p/12370445.html
Copyright © 2011-2022 走看看