dic.prog
资源名称:leda.tar.gz [点击查看]
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:1k
源码类别:
数值算法/人工智能
开发平台:
MultiPlatform
- Using a dictionary to count the number of occurrences of the elements in
- a sequence of strings, terminated by string ``stop''.
- smallskip
- #include <LEDA/dictionary.h>
- smallskip
- main()\
- ${$
- hspace*{.5cm} dictionary<string,int> $D$;
- smallskip
- hspace*{.5cm} string $s$;\
- hspace*{.5cm} dic_item $it$;
- smallskip
- hspace*{.5cm} {bf while} (cin >> $s$)
- hspace*{1.5cm} ${$ $it = D$.lookup($s$);\
- hspace*{1.85cm} if ($it==nil$) $D$.insert($s,1$);\
- hspace*{1.85cm} else $D$.change_inf($it$,$D$.inf($it$)+1);\
- hspace*{1.5cm} $}$
- smallskip
- hspace*{.5cm} {bf forall_items}($it,D$)
- cout << $D$.key($it$) << `` : " << $D$.inf($it$) << endl;\
- smallskip
- $}$\