using System;
using System.Collections.Generic;
class Program
{
private const int SIZE = 256;
private static bool Compare(char[] arr_str, char[] arr_sub) {
for (int i = 0; i < SIZE; ++i) {
if (arr_str[i] != arr_sub[i])
return false;
}
return true;
}
public static List<int> find_substring_permutations(string str, string sub) {
List<int> result_list = new List<int>();
char[] countSub = new char[SIZE];
char[] countStr = new char[SIZE];
for (int i = 0; i < sub.Length; i++) {
countSub[sub[i]]++;
countStr[str[i]]++;
}
for (int i = sub.Length; i < str.Length; i++) {
if (Compare(countSub, countStr))
result_list.Add((i - sub.Length));
countStr[str[i]]++;
countStr[str[i - sub.Length]]--;
}
if (Compare(countSub, countStr))
result_list.Add(str.Length - sub.Length);
return result_list;
}
static void Main() {
// 0 CBA : 5 BAC : 11 ABC : 12 BCA : 13 CAB : 21 ACB : 26 CAB
string s = "CBAxyBACdarABCABbcapoACBqtCAB";
string sub = "ABC";
List<int> result = find_substring_permutations(s, sub);
Console.WriteLine(string.Join(" ", result));
}
}
/*
run:
0 5 11 12 13 21 26
*/