华为机试 字符串最后一个单词的长度

题目描述

计算字符串最后一个单词的长度,单词以空格隔开。

输入描述:

一行字符串,非空,长度小于5000。

输出描述:

整数N,最后一个单词的长度

示例1

输入

hello world

输出

5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            
               // Console.WriteLine("请输入字符串");
                string str=Console.ReadLine();
                //string str="""";
                string [] a =str.Split(' ');
                int b= a[a.Length-1].Length;
                Console.WriteLine(b);
                Console.ReadKey();
        }
    }
}

 

posted @ 2020-03-20 15:40  心有玲曦遇奇缘  阅读(176)  评论(0编辑  收藏  举报