package com.kuang.demo01; import java.util.Scanner; public class Main { static class ListK{ int val; ListK pre; ListK next; public ListK(){ } public ListK(int val){ this.val = val; } } static ListK head = new ListK(); static ListK nail = new ListK(); public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()){ int n = in.nextInt(); int m = in.nextInt(); ListK headp = head; for(int i = 1 ; i <= n; i++){ ListK newNode = new ListK(i); headp.next = newNode; newNode.pre = headp; headp = newNode; } headp.next = nail; nail.pre = headp; int mcount = 0; for(int i = 0 ;i < m; i++){ int op = in.nextInt(); if(op == 1){ if(mcount != 0){ if(mcount % 2 == 0){ }else{ headp = head.next; while(headp != nail){ int tempVal = headp.val; headp.val = headp.next.val; headp.next.val = tempVal; headp = headp.next.next; } } mcount = 0; }else{ } ListK moveNode = head.next; head.next.next.pre = head; head.next = head.next.next; nail.pre.next = moveNode; moveNode.pre = nail.pre; moveNode.next = nail; nail.pre = moveNode; }else{ mcount ++; } } if(mcount != 0){ if(mcount % 2 == 0){ }else { headp = head.next; while (headp != nail) { int tempVal = headp.val; headp.val = headp.next.val; headp.next.val = tempVal; headp = headp.next.next; } } } head = head.next; while(head != nail){ System.out.print(head.val+" "); head = head.next; } System.out.println(); } } }
全部评论
(1) 回帖