Problem Description
Time limit: 1 seconds
Space limit: 32768K
The cows become blackened and want to destroy the Earth. But he forgot the password to turn on the Earth Destroyer. Niuniu has a string s, Niu Niu also remember to remove a character from S is exactly the correct password, please help the cow to find out how many times he needs to try the password.
As shown in the example s = "ABA", 3 possible passwords are "BA", "AA", "AB".
When s = "A", the only password that the cow can try is an empty password, so the output is 1.
Input Description:
The input includes a string s, length of string (1≤LENGTH≤50), which are uppercase letters from ' A ' to ' Z '.
Output Description:
Outputs an integer that indicates the maximum number of times a cow must attempt a password.
Input Example 1:
ABA
Output Example 1:
3
Problem Solving Ideas:A single occurrence of a character//multiple side-by character
1(functionMian () {2 varline = ReadLine (). Split (');3 varArr=line[0];4 varCount=0;5 for(vari=0;i<arr.length;i++){6 if(arr[i-1]!=arr[i]&&arr[i+1]!=Arr[i]) {7count++;8}Else if(arr[i-1]==arr[i]&&arr[i+1]!=Arr[i]) {9count++;Ten } One } A print (count); -})();
Password
JavaScript programming solves the problem of black cattle and cows