Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. class Solution {
  6. static void Main(String[] args) {
  7. int q = Convert.ToInt32(Console.ReadLine());
  8. for(int a0 = 0; a0 < q; a0++){
  9. string s = Console.ReadLine();
  10. var first = checkBeautifulNumericString(s);
  11. if(first > 0)
  12. Console.WriteLine("YES {0}", first);
  13. else
  14. Console.WriteLine("NO");
  15. }
  16. }
  17. static long checkBeautifulNumericString(string str){
  18. var maxSplit = str.Length / 2;
  19. for(var i = 1; i <= maxSplit; i++){
  20. var numLength = i;
  21. var first = long.Parse(str.Substring(0, i));
  22. if(first == 0){
  23. return 0;
  24. }
  25. var endPosition = i;
  26. long current = first;
  27. while(endPosition < str.Length)
  28. {
  29. if((current+1).ToString().Length > numLength)
  30. numLength++;
  31. if(endPosition + numLength > str.Length){
  32. break;
  33. }
  34. var next = long.Parse(str.Substring(endPosition, numLength));
  35. if(next != current + 1){
  36. break;
  37. }
  38. current = next;
  39. endPosition += numLength;
  40. }
  41. if(endPosition == str.Length)
  42. return first;
  43. }
  44. return 0;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement