Advertisement
stanevplamen

02.09.05.01.PHPVariables

Jul 12th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. class PHPVariables
  6. {
  7.     static void Main()
  8.     {
  9.         bool inCommentMulti = false;
  10.         List<string> variableNames = new List<string>();
  11.         while (true)
  12.         {
  13.             bool inCommentLine = false;
  14.             string currentLine = Console.ReadLine();
  15.             if (currentLine == "?>")
  16.             {
  17.                 break;
  18.             }
  19.             for (int i = 0; i < currentLine.Length; i++)
  20.             {
  21.                 if ( (currentLine[i] == '#')||(i+1< currentLine.Length && currentLine[i] == '/' && currentLine[i + 1] == '/')  )
  22.                 {
  23.                     inCommentLine = true;
  24.                 }
  25.                 else if ((i + 1 < currentLine.Length && currentLine[i] == '/' && currentLine[i + 1] == '*') )
  26.                 {
  27.                     inCommentMulti = true;
  28.                 }
  29.                 if ((inCommentMulti == true) && (i + 1 < currentLine.Length && currentLine[i] == '*' && currentLine[i + 1] == '/'))
  30.                 {
  31.                     inCommentMulti = false;
  32.                 }
  33.  
  34.                 if (inCommentLine == false && inCommentMulti == false)
  35.                 {
  36.                     StringBuilder sb = new StringBuilder();
  37.                     if (currentLine[i] == '$')
  38.                     {
  39.                         if (i - 1 >= 0 && currentLine[i - 1] == '\\' && i - 2 >= 0 && currentLine[i - 2] != '\\')
  40.                         {
  41.                             continue;
  42.                         }
  43.                         for (int j = i + 1; j < currentLine.Length; j++)
  44.                         {
  45.                             if ( ((int)(currentLine[j]) >= 65 && (int)(currentLine[j]) <= 90) ||
  46.                                 ((int)(currentLine[j]) >= 48 && (int)(currentLine[j]) <= 57) ||
  47.                                 ((int)(currentLine[j]) >= 97 && (int)(currentLine[j]) <= 122) || (int)(currentLine[j]) == 95)
  48.                             {
  49.                                 sb.Append(currentLine[j]);
  50.                             }
  51.                             else
  52.                             {
  53.                                 i = j;
  54.                                 variableNames.Add(sb.ToString());
  55.                                 break;
  56.                             }
  57.                         }
  58.                     }
  59.                 }
  60.  
  61.             }
  62.         }
  63.         variableNames = QuickSortFunction(variableNames);
  64.         string current = String.Empty;
  65.         int counterVars = 0;
  66.         StringBuilder newSB = new StringBuilder();
  67.         for (int i = 0; i < variableNames.Count; i++)
  68.         {
  69.             if (current == variableNames[i])
  70.             {
  71.                 continue;
  72.             }
  73.             counterVars++;
  74.             current = variableNames[i];
  75.             newSB.AppendLine(current);
  76.         }
  77.         Console.WriteLine(counterVars);
  78.         Console.WriteLine(newSB.ToString());
  79.     }
  80.  
  81.     static List<string> QuickSortFunction(List<string> currentArrayList)
  82.     {
  83.         if (currentArrayList.Count <= 1)
  84.         {
  85.             return currentArrayList;
  86.         }
  87.  
  88.         int measuringSign = currentArrayList.Count / 2;
  89.         string valueSign = currentArrayList[measuringSign];
  90.         currentArrayList.RemoveAt(measuringSign);
  91.  
  92.         List<string> smaller = new List<string>();
  93.         List<string> bigger = new List<string>();
  94.  
  95.         int counter = 0;
  96.         foreach (var item in currentArrayList)
  97.         {
  98.             if (true)
  99.             {
  100.                 if (string.Compare(item, valueSign, StringComparison.Ordinal) < 0)//((int)item[0] < (int)valueSign[0])
  101.                 {
  102.                     smaller.Add(item);
  103.                 }
  104.                 else
  105.                 {
  106.                     bigger.Add(item);
  107.                 }
  108.             }
  109.             counter++;
  110.         }
  111.         List<string> resultArrayList = new List<string>();
  112.         resultArrayList.AddRange(QuickSortFunction(smaller));
  113.         resultArrayList.Add(valueSign);
  114.         resultArrayList.AddRange(QuickSortFunction(bigger));
  115.         return resultArrayList;
  116.     }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement