当前位置:网站首页>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;
}
边栏推荐
- 全新BMW i3的操控,能符合对3系之名产品的期待吗?
- Spectre record
- LeetCode 583. Deleting two strings
- ROS2之OpenCV人脸识别foxy~galactic~humble
- Leetcode points to offer 30 Stack containing min function
- Cisco, Huawei network equipment
- LeetCode 5259. Calculate the total tax payable
- JUC atomic array
- I have summarized the knowledge points of JS [intermediate and advanced] for you
- LeetCode 343. integer partition
猜你喜欢

线上调试工具Arthas基础

acwing 789. Range of numbers (dichotomy + suitable for understanding dichotomy boundary)

(state compression dp+good) acwing 291 Mondrian's dream

【pytorch环境安装搭建】

(bfs+GOOD) acwing 845. Eight digit

C language: dynamic memory management

(tree DP) acwing 285 A dance without a boss

Online debugging tool Arthas advanced

How Simulink adds modules to the library browser

Exporting MySQL data table documents using Navicat
随机推荐
(dfs) acwing 842. Arrange numbers
LeetCode 5259. Calculate the total tax payable
[implementation of depth first search]
Amadahl's Law (a little thought)
Jenkins integrates LDAP. The problem of login failure of Jenkins users caused by LDAP configuration error is solved
Calculate the number of days between two times (supports cross month and cross year)
@Value不生效及extend/implement其他类无法注入bean的手动注入
Yolov5 model evaluation
LeetCode 6096. 咒语和药水的成功对数(二分查找)
LeetCode 6096. Success logarithm of spells and potions (binary search)
Exploitation of competitive loopholes in attacking and defending world PWN play conditions
Longadder of the source code of JUC atomic accumulator
谨记! 写代码别太自信! 一定要写点关键日志info输出,不然问题都定位不到。
静态变量与一个类相关联,只要该类在内存中(只要您的应用程序终止,该变量就不存在)就可以使用。(堆本体,栈引用)
LeetCode 6097. 替换字符后匹配(字典)
Jenkins集成Ldap,Ldap配置错误导致jenkins用户登录失败问题解决
Simple implementation of database link pool
C language: Simulated Implementation of library function strcpy
Alibaba senior experts analyze the standard design of protocol
LeetCode 583. 两个字符串的删除操作