Click here to Skip to main content
15,898,035 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Need cut optimization algorith Pin
xx77abs14-Sep-09 6:50
xx77abs14-Sep-09 6:50 
QuestionSearch for repeated character combinations algorithm Pin
khalidelmeknesi9-Sep-09 2:31
khalidelmeknesi9-Sep-09 2:31 
AnswerRe: Search for repeated character combinations algorithm Pin
Richard MacCutchan9-Sep-09 3:01
mveRichard MacCutchan9-Sep-09 3:01 
GeneralRe: Search for repeated character combinations algorithm Pin
khalidelmeknesi9-Sep-09 20:50
khalidelmeknesi9-Sep-09 20:50 
AnswerRe: Search for repeated character combinations algorithm Pin
Luc Pattyn9-Sep-09 12:23
sitebuilderLuc Pattyn9-Sep-09 12:23 
GeneralRe: Search for repeated character combinations algorithm Pin
khalidelmeknesi11-Sep-09 0:38
khalidelmeknesi11-Sep-09 0:38 
GeneralRe: Search for repeated character combinations algorithm Pin
Luc Pattyn11-Sep-09 1:14
sitebuilderLuc Pattyn11-Sep-09 1:14 
GeneralRe: Search for repeated character combinations algorithm [modified] Pin
khalidelmeknesi16-Sep-09 22:46
khalidelmeknesi16-Sep-09 22:46 
I have found this example but it is not 100 % good. Could you please have a look?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string _givenString = "wvtnfhxyz1hdxyz1fdxyz1ejxyz1dhxyz1dxyz1eeaa1oeys";
            Dictionary<string, int> _codes = new Dictionary<string, int>();
            int _startingPoint = 0;
            while (_startingPoint < _givenString.Length)
            {
                for (int j = 2; j < _givenString.Length; j++)
                {
                    for (int i = _startingPoint; i < _givenString.Length && i + j < _givenString.Length; i++)
                    {
                        if (!_codes.ContainsKey(_givenString.Substring(i, j)))
                        {
                            _codes.Add(_givenString.Substring(i, j), 1);
                        }
                        else
                        {
                            _codes[_givenString.Substring(i, j)] += 1;
                        }
                    }
                }
                
                _startingPoint++;
            }

            List<KeyValuePair<string, int>> _sortedCodes = SortDictionary(_codes);
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(_sortedCodes[i].Key + " : " + _sortedCodes[i].Value + " times");
            }
            Console.ReadKey();
        }

        public static List<KeyValuePair<string, int>> SortDictionary(Dictionary<string, int> data)
        {
            List<KeyValuePair<string, int>> result =
                  new List<KeyValuePair<string, int>>(data);
            result.Sort(
              delegate(
                KeyValuePair<string, int> first,
                KeyValuePair<string, int> second)
              {
                  return second.Value.CompareTo(first.Value);
              }
              );
            return result;
        }
    }
}


modified on Thursday, September 17, 2009 8:15 AM

GeneralRe: Search for repeated character combinations algorithm Pin
Luc Pattyn17-Sep-09 2:05
sitebuilderLuc Pattyn17-Sep-09 2:05 
GeneralRe: Search for repeated character combinations algorithm Pin
khalidelmeknesi17-Sep-09 2:18
khalidelmeknesi17-Sep-09 2:18 
GeneralRe: Search for repeated character combinations algorithm Pin
Luc Pattyn17-Sep-09 3:31
sitebuilderLuc Pattyn17-Sep-09 3:31 
AnswerRe: Search for repeated character combinations algorithm [modified] Pin
Moreno Airoldi12-Sep-09 4:40
Moreno Airoldi12-Sep-09 4:40 
AnswerRe: Search for repeated character combinations algorithm Pin
Member 419459314-Sep-09 7:04
Member 419459314-Sep-09 7:04 
Question[Message Deleted] Pin
kabirbdboy8-Sep-09 23:35
kabirbdboy8-Sep-09 23:35 
AnswerRe: help me to select my project Pin
CPallini9-Sep-09 1:53
mveCPallini9-Sep-09 1:53 
AnswerRe: help me to select my project Pin
Richard MacCutchan9-Sep-09 3:02
mveRichard MacCutchan9-Sep-09 3:02 
General[Message Deleted] Pin
kabirbdboy9-Sep-09 15:25
kabirbdboy9-Sep-09 15:25 
GeneralRe: help me to select my project Pin
Tim Craig9-Sep-09 17:56
Tim Craig9-Sep-09 17:56 
GeneralRe: help me to select my project Pin
kabirbdboy10-Sep-09 1:38
kabirbdboy10-Sep-09 1:38 
GeneralRe: help me to select my project Pin
Richard MacCutchan9-Sep-09 21:37
mveRichard MacCutchan9-Sep-09 21:37 
AnswerRe: help me to select my project Pin
Nagy Vilmos10-Sep-09 9:41
professionalNagy Vilmos10-Sep-09 9:41 
GeneralRe: help me to select my project Pin
kabirbdboy10-Sep-09 15:08
kabirbdboy10-Sep-09 15:08 
GeneralRe: help me to select my project Pin
Tim Craig10-Sep-09 19:30
Tim Craig10-Sep-09 19:30 
QuestionGradient map Pin
Sauce!8-Sep-09 6:21
Sauce!8-Sep-09 6:21 
AnswerRe: Gradient map Pin
Eddy Vluggen8-Sep-09 11:13
professionalEddy Vluggen8-Sep-09 11:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.