Advertisement
Guest User

Patrickssj6

a guest
Nov 12th, 2011
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Z_Boxen
  7. {
  8.     class ZBoxen
  9.     {
  10.         public struct s_ZBoxen
  11.         {
  12.             public int Index;
  13.             public char String;
  14.             public int ZBoxCount;
  15.         }
  16.  
  17.         const char DELIMITER = '$';
  18.         s_ZBoxen[] ZBoxenArray;
  19.  
  20.         public s_ZBoxen[] GetZBoxenArray()
  21.         { return this.ZBoxenArray; }
  22.  
  23.         public ZBoxen(string inputString) : this(inputString,string.Empty)
  24.         {  }
  25.  
  26.         public ZBoxen(string inputString, string inputPattern)
  27.         {
  28.             string tempString;
  29.  
  30.             if (string.IsNullOrEmpty(inputPattern))
  31.             {
  32.                 tempString = inputString;
  33.             }
  34.             else
  35.             {
  36.                 tempString = inputPattern;
  37.                 tempString += DELIMITER;
  38.                 tempString += inputString;
  39.            
  40.             }
  41.  
  42.             ZBoxenArray = new s_ZBoxen[tempString.Length];
  43.  
  44.             for (int i = 0; i < ZBoxenArray.Length; i++)
  45.             {
  46.                 ZBoxenArray[i].Index = i;
  47.                 ZBoxenArray[i].String = tempString[i];
  48.                 ZBoxenArray[i].ZBoxCount = 0;
  49.            
  50.             }
  51.  
  52.             ZBoxenArray[0].ZBoxCount = -1;
  53.  
  54.             this.BerechneZBoxen();
  55.         }
  56.  
  57.         private void BerechneZBoxen()
  58.         {
  59.            
  60.             for(int i = 1; i < ZBoxenArray.Length; i++)
  61.             {
  62.                 int tempCount = 0;
  63.                 for (int j = 0; j < ZBoxenArray.Length; j++)
  64.                 {
  65.                     if (i + j >= ZBoxenArray.Length)
  66.                     { ZBoxenArray[i].ZBoxCount = tempCount; break; }
  67.  
  68.                     if (ZBoxenArray[i+j].String == ZBoxenArray[j].String)
  69.                     {
  70.                         ++tempCount;
  71.                         continue;
  72.                     }
  73.                     else
  74.                     {
  75.                         ZBoxenArray[i].ZBoxCount = tempCount; break;
  76.                     }
  77.                    
  78.                 }
  79.             }
  80.        
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement