Advertisement
Guest User

Untitled

a guest
Sep 16th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication57
  8. {
  9. class Program
  10. {
  11. static public bool equals_sign_check(string str, int i)
  12. {
  13.  
  14. if (str[i] == '=')
  15. {
  16. if (i - 1 >= 0)
  17. if (str[i - 1] == '=' || str[i - 1] == '<' || str[i - 1] == '>')
  18. return true;
  19. if (i + 1 < str.Length)
  20. if (str[i + 1] == '=')
  21. return true;
  22. return false;
  23. }
  24. else
  25. return false;
  26. }
  27. static public bool CountBrackets(string str)
  28. {
  29. int open = 0;
  30. int close = 0;
  31. for (int i = 0; i < str.Length; ++i)
  32. if (str[i] == '(')
  33. ++open;
  34.  
  35. for (int i = 0; i < str.Length; ++i)
  36. if (str[i] == ')')
  37. ++close;
  38. if (open == close)
  39. return true;
  40. else
  41. return false;
  42. }
  43. static string alph = "qwertyuiopasdfghjklzxcvbnm";
  44. static string valid = "&|<>()";
  45. static public bool Validate(string str)
  46. {
  47. if (str == "")
  48. return false;
  49. for (int i = 0; i < str.Length; ++i)
  50. if (!((alph.Contains(str[i]) || valid.Contains(str[i]) || equals_sign_check(str, i)) && CountBrackets(str)))
  51. return false;
  52. return true;
  53.  
  54. }
  55. static void Main(string[] args)
  56. {
  57. string line = Console.ReadLine();
  58. Console.WriteLine(Validate(line));
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement