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