当前位置:网站首页>OJ daily practice - word length
OJ daily practice - word length
2022-06-22 23:33:00 【KJ. JK】
Problem description :
Enter a line of word sequence , Between adjacent words by 1 Space or spaces , Please calculate the length of each word accordingly .
Be careful , If there's punctuation ( Such as hyphen , comma ), Punctuation is counted as part of the word associated with it . There is no open space between strings , All count as words .
Input
A line of words , least 1 Word , most 300 Word , Use at least... Between words 1 Space space . The total length of the word sequence does not exceed 1000.
Output
Output the length of the corresponding word in turn , They are separated by commas .
Examples
Input
She was born in 1990-01-02 and from Beijing city.
Output
3,3,4,2,10,3,4,7,5
Java Code :
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int sum=0;
String a=in.nextLine();
String b=a.replaceAll(" +", " ");
char c[]=b.toCharArray();
for(int i=0;i<c.length;i++) {
if(c[i]==' ') {
System.out.print(sum+",");
sum=0;
}
else {
sum++;
if(i==c.length-1) {
System.out.println(sum);
}
}
}
}
}
author :KJ.JK
If the article is helpful to you , Welcome to praise or star, Your support is the greatest encouragement to the author , The shortcomings can be corrected in the comments section , Communication and learning
边栏推荐
- Spark RDD Programming Guide(2.4.3)
- os. When the command line parameter in args[1:] is empty, the internal statement will not be executed
- Future alternatives to IPv4! Read the advantages, features and address types of IPv6
- js图片分辨率压缩
- IPV4的未来替代品!一文读懂IPV6的优势特点和地址类型
- Leakcanary source code (2)
- 2020-12-20
- flutter外包,承接flutter项目
- 2021-08-21
- 【Kubernetes 系列】Kubernetes 概述
猜你喜欢

Ensure database and cache consistency

同步电路与跨时钟域电路设计2——多bit信号的跨时钟域传输(FIFO)

ArcGIS application (20) the ArcGIS grid image symbol system prompts "this dataset does not have valid histogram required for classificati..."

2021-04-14

Enjoy high-performance computing! Here comes the Tianyi cloud HPC solution

优化——线性规划

异步FIFO

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!

10 Super VIM plug-ins, I can't put them down

2021-04-16
随机推荐
使用smart-doc自动生成接口文档
OJ每日一练——病毒的增生
Smart data won two annual awards at the second isig China Industrial Intelligence Conference
2021-04-05
2021-01-29
js----SVG转PNG
SourceTree版本管理常用操作
同步电路与跨时钟域电路设计2——多bit信号的跨时钟域传输(FIFO)
Do domestic mobile phones turn apples? It turned out that it was realized by 100 yuan machine and sharp price reduction
2020-12-04
14. 最长公共前缀
js图片分辨率压缩
SqlServer 复制表的自增属性
Unity:利用 射线Ray 检测物体
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
Three cache methods and principles
OJ每日一练——过滤多余的空格
Array and string offset access syntax with curly braces is no longer support
2021-04-14
2021-04-14