当前位置:网站首页>4-5 count words and spaces (15 points)
4-5 count words and spaces (15 points)
2022-06-30 03:17:00 【Cute little white rabbit】
Yes 3 Line text , Find out how many spaces and words there are ( Specify one or more spaces between words ). If a word ends right at the end of a line , There should be a space at the beginning of the next line , There should also be spaces after periods and commas .
Input format :
There are multiple sets of test data , Processing to the end of the file . Enter three lines of text for each group ( No more than... Per line 80 Characters ).
Output format :
Each group outputs three lines of words and spaces .
sample input :
Here's a set of inputs . for example :
Math, English, C Language.
Data structure. Linear list, Stack, Queue,
and String, Array, Tree, Graph, Search, Sorting.
sample output :
Here is the corresponding output . for example :
17 27Be careful : The description of the topic is misleading , I've been popping for a long time , Just learned from the classmate's code
The title should be like this : There is one or more spaces between words , There may be spaces at the beginning of each line , Periods and Commas ( There are no periods and commas at the end of the line ) There is a space after the .
Also note that output occurs every three lines of input
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main(void)
{
//cnt Indicates the number of lines entered ,cnt1 It's the number of words ,cnt2 Is the number of spaces
int cnt {}, cnt1 {}, cnt2 {};
string s;
while ( getline(cin, s) ) {
cnt ++;
for ( int i=0; i<s.size(); i++ ) {
if ( s[i]==' ' ) {
if ( isalpha(s[i+1]) )
cnt1 ++, cnt2 ++;
else
cnt2 ++;
}
}
if ( isalpha(s[0]) )
cnt1 ++;
// Remember to count the words after each output cnt1 And number of spaces cnt2 Zero clearing
if ( cnt==3 ) {
cout << cnt1 << ' ' << cnt2 << endl;
cnt1 = cnt2 = cnt = 0;
}
}
return 0;
}边栏推荐
- Use of Arthas
- Visual HTA form designer htamaker interface introduction and usage, Download | HTA VBS visual script writing
- 广播模块代码在autojs4.1.1版本运行正常,但在pro7.0版本上运行报错(未解决)
- shell统计某个字符串最后一次出现的位置之前的所有字符串
- Link garbled escape character
- 【直播笔记0629】 并发编程二:锁
- 个人PC安装软件
- 行政路线编码 字母+数字的排序方式
- Customize the buttons of jvxetable and the usage of $set under notes
- Azure developer news flash list of events of developers in June
猜你喜欢

【直播笔记0629】 并发编程二:锁

golang bilibili直播弹幕姬

Use of Arthas

Simple custom MVC optimization

MySQL extracts strings from table fields

Compile a DLL without import table

Customize the buttons of jvxetable and the usage of $set under notes

O & M (20) make and start USB flash disk and install win10

Use compose to realize the effect of selecting movie seats by panning tickets

Prompt learning a blood case caused by a space
随机推荐
New edition of diazotization process in 2022 and analysis of diazotization process
【十分钟】manim安装 2022
Compile a DLL without import table
个人PC安装软件
Servlet面试题
Note the use of export/import and class inheritance in ES6
链接乱码转义符
Problem record: FEL_ lib. c:26:10: fatal error: libusb. h: There is no such file or directory
ZABBIX trigger explanation
Knowledge points of 2022 system integration project management engineer examination: software quality assurance and quality evaluation
什么是外链和内链?
一篇文章带你入门vim
发现mariadb数据库时间晚了12个小时
Global and Chinese market of ULTRACENTRIFUGES 2022-2028: Research Report on technology, participants, trends, market size and share
The next change direction of database - cloud native database
O & M (20) make and start USB flash disk and install win10
Some common functions and precautions
Prompt learning a blood case caused by a space
X Book 6.97 shield unidbg calling method
GTK interface programming (II): key components