Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
AlphabeticalRank
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; namespace Rextester { public class Program { public static void Main(string[] args) { var testArray = new []{ "DACB", "CA", "FLCR", "RTZX" }; foreach (var test in testArray) { Console.WriteLine("Alphabetical rank of \"{0}\": {1}", test, AlphabeticalRank(test)); } } public static int AlphabeticalRank(string s) { var rankingArray = new List<char>(s.ToCharArray()); rankingArray.Sort(); var score = 1; //this is the lowest possible rank for(int i = 0; i < s.Length -1; i++){ var rank = rankingArray.IndexOf(s[i]); score += Factorial(rank) * rank; rankingArray.RemoveAt(rank); } return score; } public static int Factorial(int n) { var product = 1; for (int i = n; i > 0; i--) { product *= i; } return product; } } }
run
|
edit
|
history
|
help
0
Captcha
to get distinct of the given array with each items occurrence count._1
C# Abstract Syntax Tree Example: Simple Pascal Compiler
Operator Overloading + Operator
Palindrome Number
nikk
generic stack implementation
Stuff
Date Time Conversion based on time zone
Composition