C#
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication4 7 { 8 class Program 9 { 10 static void Main(string[] args) 11 { 12 List<int> originalList = new List<int>(); 13 for (int i = 1; i <= 5; i++) 14 { 15 originalList.Add(i); 16 } 17 Console.Write("源数组:"); 18 foreach (int item in originalList) 19 { 20 Console.Write(item + " "); 21 } 22 Console.WriteLine(); 23 List<List<int>> resultList = new List<List<int>>(); 24 // 每一次由底至上地上升 25 for (int i = 0; i < originalList.Count; i++) 26 { 27 List<int> subList = new List<int>(); 28 for (int j = 0; j < originalList.Count; j++) 29 { 30 if (j != i) 31 { 32 subList.Add(originalList[j]); 33 } 34 } 35 resultList.Add(subList); 36 } 37 for (int i = 0; i < resultList.Count; i++) 38 { 39 List<int> subList = resultList[i]; 40 Console.Write("子数组" + (i + 1) + ":"); 41 for (int j = 0; j < subList.Count; j++) 42 { 43 Console.Write(subList[j] + " "); 44 } 45 Console.WriteLine(); 46 } 47 Console.WriteLine("子数组的数量:" + resultList.Count); 48 Console.ReadKey(); 49 } 50 } 51 }
JS
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title></title> 6 7 </head> 8 <body> 9 <script language="javascript" type="text/javascript"> 10 var origianlList = []; 11 for (var i = 1; i <= 6 ; i++) { 12 origianlList[origianlList.length] = i; 13 } 14 document.write("源数组:"); 15 for (var item in origianlList) { 16 document.write(item + " "); 17 } 18 document.write("<br/>"); 19 var resultList = []; 20 for (var i = 0 ; i < origianlList.length ; i++) { 21 var subList = []; 22 for (var j = 0 ; j < origianlList.length ; j++) { 23 if (j != i) { 24 subList[subList.length] = origianlList[j]; 25 } 26 } 27 resultList[resultList.length] = subList; 28 } 29 for (var i = 0 ; i < resultList.length ; i++) { 30 var subList = resultList[i]; 31 document.write("子数组" + (i + 1) + ":"); 32 for (var j = 0 ; j < subList.length ; j++) { 33 document.write(subList[j] + " "); 34 } 35 document.write("<br/>"); 36 } 37 document.writeln("子数组的数量:" + resultList.length); 38 </script> 39 </body> 40 </html>
Java
1 import java.util.ArrayList; 2 import java.util.List; 3 4 public class Test { 5 6 public static void main(String[] args) { 7 int score[] = { 1,2,3,4 }; 8 List<List<Integer>>list=new ArrayList<List<Integer>>(); 9 // 每一次由底至上地上升 10 for (int i = 0; i < score.length; i++) { 11 List<Integer>array=new ArrayList<Integer>(); 12 for (int j = 0; j < score.length; j++) { 13 if (j != i) { 14 array.add(score[j] ); 15 } 16 } 17 list.add(array); 18 } 19 for (List<Integer> l : list) { 20 System.out.println(l); 21 } 22 } 23 }