当前位置:网站首页>[daily question] - Huawei machine test 01
[daily question] - Huawei machine test 01
2022-07-02 06:48:00 【Xiexishan】
【 A daily topic 】— Huawei machine test 01
subject :HJ1 The length of the last word in the string
describe
Calculate the length of the last word in the string , Words are separated by spaces , String length is less than 5000.( notes : The end of the string does not end with a space )
Input description :
The input line , Represents the string to be evaluated , Non empty , The length is less than 5000.
Output description :
Output an integer , Represents the length of the last word of the input string .
Example 1
Input :
hello nowcoder
Copy
Output :
8
Copy
explain :
The last word is nowcoder, The length is 8
Ideas :
- Use gets Enter a string
When reading a string :
scanf() With Space、Enter、Tab End one input
gets() With Enter End input ( The space does not end ), Accept spaces , Will abandon the last carriage return !
2. Count from back to front , Until I met Space end .
️ The code is as follows
# define _CRT_SECURE_NO_WARNINGS 1
// Calculate the length of the last word in the string , Words are separated by spaces , String length is less than 5000.( notes : The end of the string does not end with a space )
#include <stdio.h>
#include <assert.h>
int the_length_of_last_word(char* str, int i)
{
int length = 0;
assert(str);
for (; i >= 0; i--)
{
if (str[i] == ' ')
{
break;
}
length++;
}
return length;
}
int main()
{
char a[5000] = {
0 };
gets(a);
int b = strlen(a) - 1;
int lengh = the_length_of_last_word(a, b);
printf("%d", lengh);
return 0;
}
Welcome to correct ! Pay attention that I'm not lost
Today's rubbish : Lifelong learning is the king .
边栏推荐
- 部署api_automation_test过程中遇到的问题
- The intern left a big hole when he ran away and made two online problems, which made me miserable
- CTF web practice competition
- The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem
- Eggjs -typeorm 之 TreeEntity 实战
- Asynchronous data copy in CUDA
- Kali latest update Guide
- Atcoder beginer contest 253 F - operations on a matrix / / tree array
- Utilisation de la carte et de foreach dans JS
- ts和js区别
猜你喜欢

Summary of advertisement business bug replay

unittest. Texttestrunner does not generate TXT test reports

Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决

Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件

Detailed definition of tensorrt data format

Pytest (1) case collection rules

Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决

默认google浏览器打不开链接(点击超链接没有反应)

20201002 vs 2019 qt5.14 developed program packaging

Sentry搭建和使用
随机推荐
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
Virtualenv and pipenv installation
FE - Weex 使用简单封装数据加载插件为全局加载方法
Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件
奇葩pip install
Usage of map and foreach in JS
eslint配置代码自动格式化
CTF three count
Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *
Asynchronous data copy in CUDA
Deployment API_ automation_ Problems encountered during test
Render minecraft scenes into real scenes using NVIDIA GPU
js中map和forEach的用法
20210306转载如何使TextEdit有背景图片
virtualenv和pipenv安装
Latex error: the font size command \normalsize is not defined problem solved
Latex compilation error I found no \bibstyle &\bibdata &\citation command
Implement strstr() II
Win电脑截图黑屏解决办法
Promise中有resolve和无resolve的代码执行顺序