The length of the last word in the string (Huawei Online Training)

Source: Internet
Author: User

Describe

Calculates the length of the last word in a string, separated by a space.

Knowledge points String, looping
Run time limit 0M
Memory limit 0
Input

A line of strings that are less than 128 in length.

Output

Integer n, the length of the last word.

Sample input Hello World
Sample output 5

#include <stdio.h>

#include <string.h>

#include LEN 1024

int main (void)

{

int Len, I, J;

Char Str[len];

Gets (str);

len = strlen (str);

if (0 = = len)

{

return 0;

}

if (< Len)

{

return-1;

}

i = len-1;

j = 0;

while (i>=0 && str[i] = = ")

{i--;}

while (i>=0 && str[i]! = ")

{

i--;

j + +;

}

printf ("%d\n", j);

return 0;

}

The length of the last word in the string (Huawei Online Training)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.