hdu 2072 单词数
来源:互联网 发布:手机导航网站源码 编辑:程序博客网 时间:2024/05/17 04:27
hdu 2072 单词数
题目描叙:给你 一串字符串,该字符串里只含有 小写字母和空格,求该字符串中 不同 的单词数。
解题思路:单纯天真的我,被WA成了 煞笔。于是去搜解题报告 。最主要还是题目没看清,没看见不同那两个字。果然还是太傻。 当完完全全看懂题目意思后,就没有思路了,去搜结题报告。 选了一个短小精悍的代码,研究了半天,有点眉目了。
#include<iostream>#include<cstdio>#include<set>#include<string>#include<cstring>using namespace std;int main(){ set<string>word; string s="";//字符串变量的值是空 char c; while(scanf("%c",&c)&&c!='#') { if(c==' ') { if(s.length()) word.insert(s);// 把 s 插入到 word中 s.clear(); // 清空 s } else if(c=='\n') { if(s.length()) word.insert(s); printf("%d\n",word.size()); word.clear(); s.clear(); } else { s+=c; } } return 0;}// set 这个容器的最大好就是它里面的元素没有重复的
以上代码要对 set 和 string 的特性特别熟悉才能写出。
给一个关于set 的 博客:http://blog.sina.com.cn/s/blog_779cf3410101389s.html
string的 用法:http://jingyan.baidu.com/article/20b68a8854f919796dec6265.html
刚八德!
0 0
- HDU 2072 单词数
- hdu 2072 单词数
- hdu 2072 单词数
- HDU 2072 单词数
- HDU 2072 单词数
- Hdu 2072 - 单词数
- Hdu 2072 单词数
- hdu 2072-单词数
- hdu 2072 单词数
- HDU 2072 单词数
- HDU 2072 单词数
- HDU 2072 单词数
- hdu 2072 单词数
- hdu 2072 单词数
- hdu 2072 单词数
- HDU 2072 单词数
- HDU 2072 单词数
- HDU 2072 单词数
- 正则表达式
- Java实现图的深度和广度优先遍历算法
- 【工具类代码】递归获取所有的子节点做删除获取用
- Android SpannableString使用例子
- 【华为oj】求一个数的指数因子
- hdu 2072 单词数
- activity给fragment传递数据
- mongodb查询的语法(大于,小于,大于或等于,小于或等于等等)
- 搜索学习——Lucene简介
- The type new View.OnClickListener(){} must implement the inherited abstract method View.OnClickListe
- Yahoo! UI Library 的介绍
- 如何成为一名数据科学家?
- Android 属性动画(Property Animation) 完全解析 (下)
- UINavigationControlle(导航视图控制器)控制下的页面跳转与值的传递(协议传值)