62,614
社区成员
发帖
与我相关
我的任务
分享
import java.math.*;
public class Libai {
public static void main(String args[]){
BigDecimal volumn = new BigDecimal("0");
for (int i=0; i<5; i++){
volumn = volumn.add(new BigDecimal("1"));
volumn = volumn.divide(new BigDecimal("2"));
}
System.out.print(volumn);
}
}
0.96875
[code=C#]
using System;
using System.Collections.Generic;
using System.Text;
namespace Sort
{
public class Sort
{
private List<String> result = new List<String>();
private char[] chang(char[] str, int m)
{
int i = 0;
char temp = str[0];
for (i = 0; i < m - 1; i++)
{
str[i] = str[i + 1];
}
str[i] = temp;
return str;
}
private void pai(char[] str, int m, int n) /* 定义全排列函数 */
{
int k;
str = chang(str, m);
if (m < n) /* 定 义 递 归 调 用 出 口 */
{
for (k = 0; k <= m; k++)
{
pai(str, m + 1, n); /* 递归调用 */
chang(str, m); /* 调用左移函数 */
}
}
else
{
String tempResult = "";
for (int i = 0; i < str.Length; i++)
{
tempResult += str[i];
}
result.Add(tempResult);
}
}
// 这是得到全排列的方法
public List<string> showResult(String numbers)
{
char[] str = numbers.ToCharArray();
pai(str, 0, str.Length);
return result;
}
}
class Program
{
static void Main(string[] args)
{
Test("01");// 2种情况
Test("0011");// 6
Test("000111");// 20
Test("00001111");// 70
Test("0000011111");// 252
}
private static void Test(string str)
{
List<string> list = new Sort().showResult(str);// 全排列
List<string> list2 = new List<string>();// 最终结果
foreach (string var in list)
{
if (!list2.Contains(var))
{
list2.Add(var);
}
}
Console.WriteLine("\n" + list2.Count);
}
}
}