指定された文字列に各文字が何回出現するかを計算する必要があります。C または C++ で実行する必要があり、任意のライブラリを使用できます。問題は、私は C/C++ 開発者ではないため、自分のコードが最適かどうか確信が持てないことです。最高のパフォーマンスのアルゴリズムを取得したいのですが、それがこの質問の主な理由です。
現在、次のコードを使用しています。
using namespace std;
...
char* text; // some text, may be very long
int text_length; // I know this value, if it can help
map<char,int> table;
map<char,int>::iterator it;
for(int i = 0; c = text[i]; i++) {
it = table.find(c);
if (it2 == table.end()) {
table[c] = 1;
} else {
table[c]++;
}
}
std::map 以外の構造を使用することもできますが、どの構造が優れているかわかりません。
ご協力いただきありがとうございます!