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;
}



2024年10月
29
0
30
0
01
0
02
0
03
0
04
0
05
0
06
0
07
0
08
0
09
0
10
0
11
0
12
0
13
0
14
0
15
0
16
0
17
0
18
0
19
0
20
0
21
0
22
0
23
0
24
0
25
0
26
0
27
0
28
0
29
0
30
0
31
0
01
0
02
0

TmmDiary / Copyright 2001 Ymirlink,Inc. & Mikage Sawatari
このアドレスにはメールを送らないで下さい.
Don't send mail to this address.
hina@mikage.to