标签:ring method public code index 输出 相同 static move
import java.util.ArrayList; import java.util.Scanner; public class Main_ADV198盾神与条状项链 { /** * @zxn */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); //项链的长度 int n = sc.nextInt(); //修改的次数 int m = sc.nextInt(); int nn[] = new int [n]; int mm[] = new int [m]; ArrayList<Integer> list = new ArrayList<Integer>(); //第一次的项链 for (int i = 0; i < nn.length; i++) { nn[i] = sc.nextInt(); list.add(nn[i]); } //修改项链 for (int i = 0; i < mm.length; i++) { //判断是添加还是删除 String str = sc.next(); //添加 if (str.equals("ADD")) { int a = sc.nextInt(); int b = sc.nextInt(); //获取要在a之前添加,获取a的下标 int c = list.indexOf(a); list.add(c, b); } //删除 if (str.equals("DEL")) { //把a删除 int a = sc.nextInt(); //获取a的下标并删除 int b = list.indexOf(a); list.remove(b); } } System.out.println(list.size()); for (int i = 0; i < list.size(); i++) { System.out.print(list.get(i)+" "); } } }
标签:ring method public code index 输出 相同 static move
原文地址:https://www.cnblogs.com/shiaguang/p/12363100.html