● Jul 8, 2001 (Sun) 20:58 - C++ #~~~~ # 便利だなあ。俺もCなんかさっさと捨ててC++を早くマスターしよう。 STLを覚えると更に便利です♪ 解説ページ 例えば,入力した単語をカウントしたい場合,以下のようなカンジ. #include <iostream> #include <string> #include <map> using namespace std; int main(int argc,char *argv[]) { map<string, int> counter; while(true) { string buff; cin >> buff; if (buff.size() == 0) continue; if (buff=="exit") break; counter[buff]++; cout << buff << endl; } cout << "Word Count" << endl; for(map<string, int>::const_iterator it = counter.begin(); it != counter.end(); it++) { cout << (*it).first << endl; cout << " " << (*it).second << endl; } return 0; } |
|