Home > Article > Web Front-end > See how the master uses javascript programming to solve the black cow problem
Time limit: 1 second
Space limit: 32768K
输入包括一个字符串S,字符串长度length(1 ≤ length ≤ 50),其中都是从'A'到'Z'的大写字母。
输出一个整数,表示牛牛最多需要尝试的密码次数。
ABA
3
(function mian(){ var line = readline().split(' '); var arr=line[0]; var count=0; for(var i=0;i<arr.length;i++){ if(arr[i-1]!=arr[i]&&arr[i+1]!=arr[i]){ count++; }else if(arr[i-1]==arr[i]&&arr[i+1]!=arr[i]){ count++; } } print(count); })();
The above is the detailed content of See how the master uses javascript programming to solve the black cow problem. For more information, please follow other related articles on the PHP Chinese website!