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;
- class PHPVariables
- {
- static void Main()
- {
- StringBuilder text = new StringBuilder();
- StringBuilder result = new StringBuilder();
- HashSet<string> existing = new HashSet<string>();
- string line = Console.ReadLine().Trim();
- while (line != "?>")
- {
- text.AppendLine(line);
- line = Console.ReadLine().Trim();
- }
- bool oneLineComment = false;
- bool moreLineComment = false;
- int counter = 0;
- for (int i = 0; i < text.Length; i++)
- {
- if (text[i].ToString() == "/" || text[i].ToString() == "#")
- {
- oneLineComment = true;
- }
- else if (text[i] == '\n')
- {
- oneLineComment = false;
- }
- else if (text[i].ToString() == "/*")
- {
- moreLineComment = true;
- }
- else if (text[i].ToString() == "*/")
- {
- moreLineComment = false;
- }
- if (!oneLineComment && !moreLineComment)
- {
- if (text[i] == '\\')
- {
- i += 2;
- }
- if (text[i] == '$')
- {
- if (char.IsNumber(text[i + 1]) || char.IsLetter(text[i + 1]) || text[i + 1] == '_')
- {
- counter++;
- i++;
- while (char.IsNumber(text[i]) || char.IsLetter(text[i]) || text[i] == '_')
- {
- result.Append(text[i]);
- i++;
- }
- existing.Add(result.ToString());
- result.Clear();
- i--;
- }
- }
- }
- }
- Console.WriteLine(counter);
- Console.WriteLine(string.Join("\n",existing));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement