当前位置:网站首页>MOOC week 8 programming exercise 1
MOOC week 8 programming exercise 1
2022-06-13 09:25:00 【Hezeze】
1 Word length (4 branch )
Topic content :
Your program reads a line of text , There are several words separated by spaces , With ‘.’ end . You want to output the length of each word in this line of text . The words here have nothing to do with language , It can include various symbols , such as “it’s” Count a word , The length is 4. Be careful , Consecutive spaces may appear in the line .
Input format :
Input gives one line of text in one line , With ‘.’ end , The ending period cannot be counted within the length of the last word .
Output format :
Output the length of the word corresponding to this line of text in one line , Each length is separated by a space , There is no final space at the end of the line .
sample input :
It’s great to see you here.
sample output :
4 5 2 3 3 4
The time limit :500ms Memory limit :32000kb
#include <stdio.h>
int main() {
char text[100];
gets(text); // Input string
int i = 0;
int count = 0;
int flag = 1;
int a[10]; // Array for counting word length
int x = 0;
while (text[i] != '.') {
if (text[i] != ' ') {
flag = 0;
count++;
} else {
flag = 1;
}
if (flag && count != 0 || text[i+1] == '.') {
// To satisfy multiple spaces and only enter . Judgment of time
a[x] = count;
count = 0;
x++;
}
i++;
}if (flag == 0) {
printf ("%d", a[0]);
}
for (i = 1; i < x; i++) {
printf (" %d", a[i]);
}
return 0;
}
边栏推荐
- LeetCode 343. 整数拆分
- 20211028 Stabilizability
- I have summarized the knowledge points of JS [intermediate and advanced] for you
- 【pytorch环境安装搭建】
- C/S模型与P2P模型
- Simple use of spiel expressions
- C language: recursive function to realize Hanoi Tower
- 20211104 why is the trace of a matrix equal to the sum of eigenvalues, and why is the determinant of a matrix equal to the product of eigenvalues
- Z字形变换
- LeetCode 5259. Calculate the total tax payable
猜你喜欢
(tree DP) acwing 285 A dance without a boss
(state compression dp+ binary) acwing 91 Shortest Hamilton path
C language: minesweeping
Dynamic display of analog clock using digital clock in turtle Library
Jenkins accédant à l'authentification de l'utilisateur openldap
(bfs) acwing 844. Labyrinth
C language: five custom types
Overview of common layers of image recognition neural network (under update)
C language: deep understanding of pointers and arrays
[implementation of depth first search]
随机推荐
C/S模型与P2P模型
Longadder of the source code of JUC atomic accumulator
The turtle library displays the system time
@Value does not take effect and extend/implement other classes cannot inject beans manually
C # introductory series (XIII) -- getting to know the structure for the first time
BGP 联邦+Community
JUC atomic reference and ABA problem
Online debugging tool Arthas advanced
LeetCode 6095. 强密码检验器 II
JUC atomic integer
Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?
turtle库的使用数字时钟模拟时钟动态显示
LeetCode 1. Sum of two numbers
LeetCode 5289. 公平分发饼干(DFS)
Lecture par lots de tous les fichiers vocaux sous le dossier
Heap
Jenkins integrates LDAP. The problem of login failure of Jenkins users caused by LDAP configuration error is solved
LeetCode 剑指 Offer 30. 包含min函数的栈
LeetCode 201. Digit range bitwise AND
C language: deep understanding of pointers and arrays