単語の配列とテキスト ファイルがあります。私がやりたいことは、単語の配列を使用してテキスト ファイルを検索し、配列内の各単語がテキスト ファイルに出現する回数を数えることです。
For ループを使用することを考えましたが、それぞれの個々の単語数ではなく、単語数の合計が得られました。テキスト ファイルには約 40000 語あるため、テキスト ファイルを配列に入れることはできません。
カウントの後、各カウントを「スケール」と呼ばれる整数値で割りたいと思います。そして、文字列に新しいカウント数を掛けます。
というわけで、現在は下図のようにしています。とにかくこれをより効率的にすることはできますか?
どんな助けでも大歓迎です。
単語の配列 = テスト単語。
ファイル名 = testF.
inWord = ファイル内の各単語。
while(testF >> inWord)
{if (inWord == testwords[0]){
count1++;
}
if (inWord == testwords[1]){
count2++;
}
if (inWord == testwords[2]){
count3++;
}
if (inWord == testwords[3]){
count4++;
}
if (inWord == testwords[4]){
count5++;
}
if (inWord == testwords[5]){
count6++;
}
if (inWord == testwords[6]){
count7++;
}
if (inWord == testwords[7]){
count8++;
}
}
cout << testwords[0] << " " << count1 << " " << s1.append(count1/scale, '*') << endl;
cout << testwords[1] << " " << count2 << " " << s2.append(count2/scale, '*') << endl;
cout << testwords[2] << " " << count3 << " " << s3.append(count3/scale, '*') << endl;
cout << testwords[3] << " " << count4 << " " << s4.append(count4/scale, '*') << endl;
cout << testwords[4] << " " << count5 << " " << s5.append(count5/scale, '*') << endl;
cout << testwords[5] << " " << count6 << " " << s6.append(count6/scale, '*') << endl;
cout << testwords[6] << " " << count7 << " " << s7.append(count7/scale, '*') << endl;
cout << testwords[7] << " " << count8 << " " << s8.append(count8/scale, '*') << endl;