/**
* 求数值在 1 - 50 之内的任意5个数之和为100 。
* 数值:1,2,3,4,5,6....48,49,50
* 取其中的任意5个数,但这5个数相加之和要等于100,并将所有这种组合罗列
* 例: 1+10+19+20+50=100
* 3+14+16+27+40=100
*/
import java.util.*;
public class TotalList {
private LinkedList list = new LinkedList();
private void TotalEqual100(int begin,int end) {
for (int i1 = begin; i1 <= end; i1++) {
for (int i2 = i1 + 1; i2 <= end; i2++) {
for (int i3 = i2 + 1; i3 <= end; i3++) {
for (int i4 = i3 + 1; i4 <=end; i4++) {
for (int i5 = i4 + 1; i5 <= end; i5++) {
int count = i1+i2+i3+i4+i5;
String str = String.valueOf(i1)+"+"+i2+"+"+i3+"+"+i4+"+"+i5;
if(count == 100)
{
str+="="+count;
if(!list.contains(str))
{
list.add(str);
}
}
}
}
}
}
}
}
private void display()
{
Iterator it = list.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
public static void main(String[] args) {
TotalList tl = new TotalList();
tl.TotalEqual100(1,50);
tl.display();
System.out.println(tl.list.size());
}
}