思路简单,但是贼鸡儿绕
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); ArrayList<String> arr=new ArrayList<String>(); while(sc.hasNextInt()){ int offset=sc.nextInt(); int n=sc.nextInt(); int l1=sc.nextInt(); int l2=sc.nextInt(); arr.add(getresult(offset,n, l1,l2)); } for(int i=0;i<arr.size();i++){ System.out.println(arr.get(i)); } } public static String getresult(int offset,int n,int l1,int l2){ int start1; int end1; int start2; int end2; if(offset<l1){ start1=offset; if(start1+n>l1){ end1=l1; start2=0; end2=start1+n-l1<l2?start1+n-l1:l2; }else{ end1=start1+n; start2=0; end2=0; } }else{ start1=l1; end1=l1; start2=offset-l1<l2?offset-l1:l2; end2=start1+n-l1<l2?start1+n-l1:l2; } return start1+" "+end1+" "+start2+" "+end2; } }