当前位置:网站首页>HDU-单词数
HDU-单词数
2022-07-16 01:29:00 【_rosy】
lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
Output
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
Sample
| Inputcopy | Outputcopy |
|---|---|
you are my friend # | 4 |
本题有一些小坑,就是可能一行中的一个单词后可能存在多个空格,或者最末尾的时候存在多个空格。比如you are i miss miss i read 中第二个i后面有两个空格,read后面有三个空格。并且考虑到我初始化字符串数组时是将他们初始化为""的,也就是说当它为空格是我的ss[i]是为""的。所以我们就直接在遍历ss数组时判断就可以解决。
#include<iostream>
#include<string>
#include<string.h>
#include<list>
#include<set>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
double a[100];
int main(){
string str,ss[1005];
set<string>se;
while(getline(cin,str)&&str!="#"){
int cnt=0;
se.clear();
fill(ss,ss+1005,"");
for(int i=0;i<str.size();i++){
if(str[i]==' '){
cnt++;
continue;
}
ss[cnt]+=str[i];
}
// for(int i=0;i<=cnt;i++){
// cout<<i<<":";
// cout<<ss[i]<<" ";
// }
for(int i=0;i<=cnt;i++){
if(ss[i]=="")continue;
se.insert(ss[i]);
}
cout<<se.size()<<endl;
}
return 0;
}
lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
Output
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
Sample
| Inputcopy | Outputcopy |
|---|---|
you are my friend # | 4 |
lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
Output
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
Sample
| Inputcopy | Outputcopy |
|---|---|
you are my friend # | 4 |
边栏推荐
- Deep learning ----- verification code
- Free SSL certificate application and deployment practice
- 自动推理的逻辑01
- Solve the "cannot find module 'path' or its corresponding type declarations." in TS
- 使用nlmeas对图像进行去噪
- TMUX usage
- Ue5 fonctions simples de détection des collisions de rôles
- 重建二叉树
- 2022年成都/杭州/厦门/武汉产品经理认证招生简章(NPDP)
- Power bi---- DAX explanation
猜你喜欢

迅为龙芯开发板国产双核64位Loognix系统双千兆以太网更多接口

圖片格式解析
![[image fusion] multi focus image fusion in DCT domain based on MATLAB [including Matlab source code, 1973]](/img/91/087665822e3b8cd2ec7f8f7f7360c7.png)
[image fusion] multi focus image fusion in DCT domain based on MATLAB [including Matlab source code, 1973]

面试高频:MySQL是怎么保证高可用的?

Solution to script loss when the prefab of unity ngui is migrated to other projects

这20道Redis经典面试题你还不会,面试官看都不看你一眼

Use of gin framework

If the designer leaves, the iphone14 may become a brick, and using the iPhone is even more compelling

私域运营为啥这么火?企业如何做好自己的私域运营呢?
![[object conversion] vo2dto use](/img/fa/5a0fefcf886fa74d3df0dead565aa5.png)
[object conversion] vo2dto use
随机推荐
Résolution du format d'image
Assembly language instruction Encyclopedia
Deep learning ----- verification code
这20道Redis经典面试题你还不会,面试官看都不看你一眼
[jailhouse article] bao: a lightweight static partitioning hypervisor for modern multi core embedded
数据库定时备份linux篇
[object header] view the bytes occupied by the object
2022年7月16日CDGA/CDGP数据治理认证考试成绩出来啦!
Appium自动化测试基础 — webview操作(重点)
Summarize the differences between i++ and i++
重建二叉树
Kettle【实践 01】Linux环境下使用Azkaban定时调用Kettle的KJB或KTR脚本实现自动化数据处理(完整流程实例分享:包含sql+ktr+shell+flow相关文件云资源)
【idea】idea添加vm options
Part 50 - Analysis of a query request header parameter [2022-07-14]
openEuler 知:SIG
Use of gin framework
UE5简单的角色碰撞检测功能
Overview of database system -- overview of data model
openEuler 知:日志查找技巧
面试高频:MySQL是怎么保证高可用的?