线性代数求一个排列的逆序数,C#程序及源码。
时间:2010-12-30 来源:/* eXplorer :D */
一怒之下写了个这个,造福一下人类。以后线带作业不高兴自己算可以用这个程序来做。
代码没什么含金量,就是偷懒用的,顺便造福一下.NET的初学者。我写的时候也偷懒了。没做界面,所以说DOS界面的。能用就行了。界面什么的都是浮云。
使用方法:输入要求逆序数的排列,然后按回车就好了。
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 namespace FuckMath
5 {
6 class Program
7 {
8 static void Main(string[] args)
9 {
10 string inputStr = Console.ReadLine();
11 int[] a = new int[inputStr.Length];
12 for (int i = 0; i < inputStr.Length; i++)
13 {
14 a[i] = Convert.ToInt32(inputStr.Substring(i, 1));
15 }
16 int count = 0;
17 for (int j = 0; j < a.Length; j++)
18 {
19 for (int k = 0; k < a.Length; k++)
20 {
21 if (j > k && a[j] < a[k])
22 {
23 count++;
24 }
25 }
26 }
27 Console.WriteLine(count);
28 Console.ReadLine();
29 }
30 }
31 }
32
相关阅读 更多 +
排行榜 更多 +