Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- class Solution {
- static void Main(String[] args) {
- int q = Convert.ToInt32(Console.ReadLine());
- for(int a0 = 0; a0 < q; a0++){
- string s = Console.ReadLine();
- var first = checkBeautifulNumericString(s);
- if(first > 0)
- Console.WriteLine("YES {0}", first);
- else
- Console.WriteLine("NO");
- }
- }
- static long checkBeautifulNumericString(string str){
- var maxSplit = str.Length / 2;
- for(var i = 1; i <= maxSplit; i++){
- var numLength = i;
- var first = long.Parse(str.Substring(0, i));
- if(first == 0){
- return 0;
- }
- var endPosition = i;
- long current = first;
- while(endPosition < str.Length)
- {
- if((current+1).ToString().Length > numLength)
- numLength++;
- if(endPosition + numLength > str.Length){
- break;
- }
- var next = long.Parse(str.Substring(endPosition, numLength));
- if(next != current + 1){
- break;
- }
- current = next;
- endPosition += numLength;
- }
- if(endPosition == str.Length)
- return first;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement