首页 > 其他 > 详细

HDU 2072 <单词数 >

时间:2016-08-30 17:22:10      阅读:129      评论:0      收藏:0      [点我收藏+]

Description

lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。

Input

有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。

Output

每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。

Sample Input

you are my friend
#

Sample Output

4
set和string是个好东西啊。

AC代码:
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string.h>
#include<string>
#include<iostream>
#include<set>
using namespace std;

char s;
string p;
set<string> q;
int main()
{
    p = "!";
    q.insert(p);
    while ((s = getchar()) != #)
    {
        if (s !=  &&s != \n)p += s;
        if (s ==  ) { q.insert(p);p = "!"; }
        if (s == \n) { q.insert(p);p = "!";printf("%d\n", q.size() - 1);q.clear();q.insert(p); }
    }

}

 


HDU 2072 <单词数 >

原文:http://www.cnblogs.com/914295860-jry/p/5822393.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!