C#(.NET核心),317,289,279字节
p=>{string r="",l=r,h=r,c="a@b8c(d6e3f#g9h#i1i!k<l1lio0q9s5s$t+v>v<wuw2x%y?";int i=0,n=p.Length,d,a=1;for(;i<n;i++){h=p[i]+"";if(h==p[(i==n-1?i:i+1)]+""&&i!=n-1)a++;else{d=c.IndexOf(h);if(d>=0&&d%2<1){l=c[d+1]+"";h=l=="u"?"uu":l;c=c.Remove(d,2);}r+=a>1?a+""+h:h;a=1;}}return r;};
在线尝试!
我希望可以将char数组作为输入而不是字符串。
Ungolfed:
string result = "", casesCharReplacement = result, currentChar = result, cases = "a@b8c(d6e3f#g9h#i1i!k<l1lio0q9s5s$t+v>v<wuw2x%y?";
int i = 0, n = pas.Length, casesIndex, charAmounts = 1;
// For every char in the pass.
for (; i < n; i++)
{
currentChar = pas[i] + "";
// if the next char is equal to the current and its not the end of the string then add a +1 to the repeated letter.
if (currentChar == (pas[(i == n - 1 ? i : i + 1)] + "") && i != n - 1)
charAmounts++;
else
{
// Finished reading repeated chars (N+Char).
casesIndex = cases.IndexOf(currentChar);
// Look for the replacement character: only if the index is an even position, otherwise I could mess up with letters like 'i'.
if (casesIndex >= 0 && casesIndex % 2 < 1)
{
casesCharReplacement = cases[casesIndex + 1]+"";
// Add the **** +u
currentChar = casesCharReplacement == "u"?"uu": casesCharReplacement;
// Remove the 2 replacement characters (ex: a@) as I won't need them anymore.
cases = cases.Remove(casesIndex, 2);
}
// if the amount of letters founded is =1 then only the letter, otherwise number and the letter already replaced with the cases.
result += charAmounts > 1 ? charAmounts + ""+currentChar : currentChar;
charAmounts = 1;
}
}
return result;