Finds a repeating substring in a data string

Source: Internet
Author: User

Enter an integer (n is an integer less than 9 digits), treated as a string,
See if there is the same substring, such as 1212, the same substring is 12,
141516 There are no substrings (the substring length must be greater than or equal to 2).
Output 1 If there is a substring of the same string, otherwise output 0
Input: Integers less than 9 in length
Output 1 or 0

The simplest way to find the same substring is to traverse, 00~99, no matter how long the same substring, must have a length of 2 substring is the same, this problem can be converted to whether there are multiple 00~99 substrings.

ImportJava.util.Scanner; Public classmain{ Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); String String=Scanner.nextline ();  for(inti=0;i<99;i++) {String str=string.format ("%02d", i);              System.out.println (str); intindex1=String.IndexOf (str); intIndex2=String.LastIndexOf (str); if(index2-index1>=2) {System.out.println (1);                  Scanner.close (); return; }} System.out.println (0);      Scanner.close (); }      }

Finds a repeating substring in a data string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.