C/C++の宿題を片付けます 62代目
■ このスレッドは過去ログ倉庫に格納されています
0062デフォルトの名無しさん
2006/03/04(土) 23:43:50ネタかとおそれつつマジレスすると、無難なところでこんな感じか。
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
int main()
{
using namespace std;
using namespace boost::lambda;
// 「while {}で文字カウント」する部分
vector<int> count(256); // int count[256];みたいなもの。文字コード0から255(==256-1)について、それぞれのカウントを格納する
int ch;
while ((ch = cin.get()) != EOF) { // 標準入力から1文字読み込み。end-of-fileが見つかるまで繰り返し
++count[ch]; // 読み込んだ文字のカウントをインクリメントする
}
// 後は何とでも
char chars[] = "aeiou";
for (int i = 0; (ch = chars[i]) != '\0'; ++i)
cout << "Number of " << ch << "'s: " << count[ch] << endl;
cout << "Number of lines: " << count['\n'] << endl;
int total = 0;
for_each(count.begin(), count.end(), (var(total) += _1));
cout << "Number of characters: " << total << endl;
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています