using System; using System.Collections.Generic; using System.Text;namespace ConsoleApplication1 { class Program //计算P(M,N) M=3;N=3 { static int Count=0; //存放排列组合数. static void Main(string[] args) { int M = 3; int N = 3; int[] a = new int[M]; for (int i = 1; i <= M; i++) //数组赋初值"1,2,3" { a[i-1] = i; } if (M < N) { } else { getValue(a, 0, N); Console.WriteLine(Count);//输出组合数 Console.Read(); } } static void getValue(int[] a, int k, int n) { int temp; if (k >= n) //输出结果: { string s = ""; for (int i = 0; i < n; i++) { s = s + a[i].ToString() + " "; } Count++; Console.WriteLine(s); } else { for (int i = k; i < a.Length; i++) { temp = a[i]; a[i] = a[k]; a[k] = temp; getValue(a, k + 1, n); //递归调用 temp = a[k]; a[k] = a[i]; a[i] = temp; } } } } }
using System; using System.Collections;namespace MyNameSpace { class GenerateWords { public static void Main() { string str = "1234"; ArrayList result = new ArrayList(); ArrayList kinds = Generate_Permutations1(str); for (int i = 0; i < kinds.Count; i++) { ArrayList res = Generate_Permutations(kinds[i].ToString()); result.AddRange(res); }
Console.WriteLine("Count = " + result.Count); for (int i = 0; i < result.Count; i++) { Console.WriteLine(result[i]); } } public static ArrayList Generate_Permutations(string word) { ArrayList result = new ArrayList(); if (word.Length == 1) { result.Add(word); return result; } for (int i = 0; i < word.Length; i++) { string shorter_word = word.Substring(0, i) + word.Substring(i + 1, word.Length - i - 1); ArrayList shorter_Permutations = Generate_Permutations(shorter_word); for (int j = 0; j < shorter_Permutations.Count; j++) { string longer_word = word[i].ToString() + shorter_Permutations[j].ToString(); result.Add(longer_word); } } return result; } public static ArrayList Generate_Permutations1(string word) { ArrayList result = new ArrayList(); result.Add(word[word.Length - 1]); if (word.Length <= 1) return result; for (int i = word.Length - 2; i >= 0; i--) { int count = result.Count; for (int j = 0; j < count; j++) { result.Add(word[i].ToString() + result[j].ToString()); } result.Add(word[i].ToString()); } return result; } } }
我下载了一份word文档,我想把它里面的格式给清除掉。我点格式-清除所有格式,结果格式是清除了,但是旁边有个小方框还标明了原来的格式,我想把那个小方框给去掉,怎么做?
http://community.csdn.net/Expert/topic/5267/5267439.xml?temp=.1484644
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program //计算P(M,N) M=3;N=3
{
static int Count=0; //存放排列组合数.
static void Main(string[] args)
{
int M = 3;
int N = 3;
int[] a = new int[M]; for (int i = 1; i <= M; i++) //数组赋初值"1,2,3"
{
a[i-1] = i;
}
if (M < N)
{
}
else
{
getValue(a, 0, N);
Console.WriteLine(Count);//输出组合数
Console.Read();
} } static void getValue(int[] a, int k, int n)
{
int temp;
if (k >= n) //输出结果:
{
string s = "";
for (int i = 0; i < n; i++)
{
s = s + a[i].ToString() + " ";
}
Count++;
Console.WriteLine(s);
}
else
{
for (int i = k; i < a.Length; i++)
{
temp = a[i];
a[i] = a[k];
a[k] = temp;
getValue(a, k + 1, n); //递归调用
temp = a[k];
a[k] = a[i];
a[i] = temp;
}
}
}
}
}
using System.Collections;namespace MyNameSpace
{
class GenerateWords
{
public static void Main()
{
string str = "1234";
ArrayList result = new ArrayList();
ArrayList kinds = Generate_Permutations1(str);
for (int i = 0; i < kinds.Count; i++)
{
ArrayList res = Generate_Permutations(kinds[i].ToString());
result.AddRange(res);
}
Console.WriteLine("Count = " + result.Count);
for (int i = 0; i < result.Count; i++)
{
Console.WriteLine(result[i]);
}
}
public static ArrayList Generate_Permutations(string word)
{
ArrayList result = new ArrayList();
if (word.Length == 1)
{
result.Add(word);
return result;
}
for (int i = 0; i < word.Length; i++)
{
string shorter_word = word.Substring(0, i) + word.Substring(i + 1, word.Length - i - 1);
ArrayList shorter_Permutations = Generate_Permutations(shorter_word);
for (int j = 0; j < shorter_Permutations.Count; j++)
{
string longer_word = word[i].ToString() + shorter_Permutations[j].ToString();
result.Add(longer_word);
}
}
return result;
} public static ArrayList Generate_Permutations1(string word)
{
ArrayList result = new ArrayList();
result.Add(word[word.Length - 1]);
if (word.Length <= 1)
return result;
for (int i = word.Length - 2; i >= 0; i--)
{
int count = result.Count;
for (int j = 0; j < count; j++)
{
result.Add(word[i].ToString() + result[j].ToString());
}
result.Add(word[i].ToString());
}
return result;
} }
}