Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace PHPVariables
- {
- class PHPVariables
- {
- static void Main(string[] args)
- {
- HashSet<string> variables = new HashSet<string>();
- StringBuilder line = new StringBuilder(Console.ReadLine());
- string commentPattern = @"([/]{1}[*]{1}.*[*]{1}[/]{1})|([/][/].*)|([#]{1}.*)|(?<multiLineComment>([/]{1}[*]{1}.*))";
- string varPattern = @"([^\\]|[\\]{2})[$]{1}(?<var>[A-Za-z0-9_]+)";
- bool multiLineComment = false;
- while (line.ToString()!="?>")
- {
- line.Insert(0, ' ');
- if (multiLineComment)
- {
- if (line[line.Length-1]=='/' && line[line.Length-2] == '*')
- {
- multiLineComment = false;
- }
- line = new StringBuilder(" ");
- }
- Match match = Regex.Match(line.ToString(), commentPattern);
- while (match.Success)
- {
- if (match.Groups["multiLineComment"].Success)
- {
- multiLineComment = true;
- }
- line.Replace(match.ToString(), "");
- match = match.NextMatch();
- }
- Match m = Regex.Match(line.ToString(), varPattern);
- while (m.Success)
- {
- variables.Add(m.Groups["var"].ToString());
- m = m.NextMatch();
- }
- line = new StringBuilder(Console.ReadLine());
- }
- List<string> list = new List<string>();
- Console.WriteLine(variables.Count);
- foreach (var item in variables)
- {
- list.Add(item);
- }
- string[] arr = list.ToArray();
- Array.Sort(arr);
- for (int i = 0; i < arr.Length; i++)
- {
- Console.WriteLine(arr[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement