C#LeetCode刷题之#893-特殊等价字符串组​​​​​​​​​​​​​​（Groups of Special-Equivalent Strings）

• 1 <= A.length <= 1000
• 1 <= A[i].length <= 20
• 所有 A[i] 都具有相同的长度。
• 所有 A[i] 都只由小写字母组成。

You are given an array A of strings.

Two strings S and T are special-equivalent if after any number of moves, S == T.

A move consists of choosing two indices i and j with i % 2 == j % 2, and swapping S[i] with S[j].

Now, a group of special-equivalent strings from A is a non-empty subset S of A such that any string not in S is not special-equivalent with any string in S.

Return the number of groups of special-equivalent strings from A.

Input: [“a”,”b”,”c”,”a”,”c”,”c”]

Output: 3

Explanation: 3 groups [“a”,”a”], [“b”], [“c”,”c”,”c”]

Input: [“aa”,”bb”,”ab”,”ba”]

Output: 4

Explanation: 4 groups [“aa”], [“bb”], [“ab”], [“ba”]

Input: [“abc”,”acb”,”bac”,”bca”,”cab”,”cba”]

Output: 3

Explanation: 3 groups [“abc”,”cba”], [“acb”,”bca”], [“bac”,”cab”]

Output: 1

Note:

• 1 <= A.length <= 1000
• 1 <= A[i].length <= 20
• All A[i] have the same length.
• All A[i] consist of only lowercase letters.

```public class Program {

public static void Main(string[] args) {
var S = "I speak Goat Latin";

var res = ToGoatLatin(S);
Console.WriteLine(res);

}

private static string ToGoatLatin(string S) {
//按空格分隔
var split = S.Split(' ');
//定义结果
var res = string.Empty;
for(var i = 0; i < split.Length; i++) {
if(IsStartsWithVowel(split[i])) {
res += split[i];
} else {
//辅音字母开头时，首字母后置
res += split[i].Substring(1) + split[i][0];
}
//追回字符串 ma 和按索引重复的字符 a
res += "ma" + RepeatString(i + 1) + " ";
}
return res.Trim();
}

private static bool IsStartsWithVowel(string word) {
//判断是不是元音字母
var s = word[0].ToString().ToLower();
return s == "a" || s == "e" || s == "i" || s == "o" || s == "u";
}

private static string RepeatString(int count) {
//重复字符串
var c = 'a';
var res = string.Empty;
for(var i = 0; i < count; i++) {
res += c;
}
return res;
}

}```

`Imaa peaksmaaa oatGmaaaa atinLmaaaaa`