当前位置:网站首页>统计单词(DAY 101)华中科技大学考研机试题
统计单词(DAY 101)华中科技大学考研机试题
2022-08-04 23:36:00 【张学恒】
1:题目
编写一个程序,读入用户输入的,以 . 结尾的一行文字,统计一共有多少个单词,并分别输出每个单词含有多少个字符。 (凡是以一个或多个空格隔开的部分就为一个单词)
输入格式
共一行,包含一个以 . 结尾的字符串。
注意,最后一个单词后面会直接跟一个 . 表示句子结束,但是该 . 并不计入单词中。
输出格式
共一行,按顺序输出字符串中每个单词包含的字母的个数。
数据范围
字符串长度不超过 1000。
输入样例:
hello how are you.
输出样例:
5 3 3 3
2:代码实现
一直读入 while (cin>> s) str[k++]=s;
把输入的数据读入到一个数组中,完成了 存储和 ++ 的过程
str[k]=s;
k++;
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1010;
string str[N];
string s;
int main()
{
int k=0;
while(cin>> s)str[k++]=s;
for(int i=0;i<k-1;i++)cout << str[i].size()<< ' ';
cout << str[k-1].size()-1;
return 0;
}
边栏推荐
- 三大技巧让你成功入门3D建模,零基础小白必看
- 安全软件 Avast 与赛门铁克诺顿 NortonLifeLock 合并案获英国批准,市值暴涨 43%
- 什么是次世代建模(附学习资料)
- CS8416国产替代DP8416 数字音频接收器
- 一点点读懂cpufreq(一)
- 社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力
- MYS-6ULX-IOT 开发板测评——使用 Yocto 添加软件包
- 文献阅读十——Detect Rumors on Twitter by Promoting Information Campaigns with Generative Adversarial Learn
- Pytorch分布式训练/多卡/多GPU训练DDP的torch.distributed.launch和torchrun
- Day118. Shangyitong: order list, details, payment
猜你喜欢
一点点读懂Thremal(二)
Basic web in PLSQL
【字符串函数内功修炼】strncpy + strncat + strncmp(二)
PID Controller Improvement Notes No. 7: Improve the anti-overshoot setting of the PID controller
如何根据地址获取函数名
深度|医疗行业勒索病毒防治解决方案
Pytest学习-Fixture
使用OpenCV实现一个文档自动扫描仪
Uniapp dynamic sliding navigation effect demo (finishing)
4-《PyTorch深度学习实践》-反向传播
随机推荐
@Async注解的作用以及如何实现异步监听机制
什么是次世代建模(附学习资料)
enumerate()函数
Nuclei (2) Advanced - In-depth understanding of workflows, Matchers and Extractors
从单体架构迁移到 CQRS 后,我觉得 DDD 并不可怕
【字符串函数内功修炼】strcpy + strcat + strcmp(一)
mysql基础
Day118.尚医通:订单列表、详情、支付
【字符串函数内功修炼】strlen + strstr + strtok + strerror(三)
typeScript-闭包函数的使用
PZK学C语言之字符串函数(一)
学生管理系统架构设计
生产者消费者问题
Since a new byte of 20K came out, I have seen what the ceiling is
Will we still need browsers in the future?(feat. Maple words Maple language)
建模师经验分享:模型学习方法
社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力
[Happy Qixi Festival] How does Nacos realize the service registration function?
ClickHouse 二级索引
使用代理对象执行实现类目标方法异常