zoukankan      html  css  js  c++  java
  • 字符串练习

    你的程序要读入一行文本,其中以空格分隔为若干个单词,以‘.’结束。你要输出这行文本中每个单词的长度。这里的单词与语言无关,可以包括各种符号,比如“it's”算一个单词,长度为4。注意,行中可能出现连续的空格。

    输入格式:

    输入在一行中给出一行文本,以‘.’结束,结尾的句号不能计算在最后一个单词的长度内。

    输出格式:

    在一行中输出这行文本对应的单词的长度,每个长度之间以空格隔开,行末没有最后的空格。

    输入样例:

    It's great to see you here.

    输出样例:

    4 5 2 3 3 4

    #include <stdio.h>
    #define M 1000
    int main()
    {
        int count,i;
        int flag = 1;
        char word[M];
        gets(word);
        count = i = 0;
        while(1)
        {
            if(count && (word[i] == ' ' || word[i] == '.'))//最后一个单词后面可能为空格或'.'
            {
                if(flag == 1)//标记,第一次输出
                {
                    printf("%d",count);
                    flag ++;
                }
                else
                    printf(" %d",count);
                count = 0;
            }
            while(word[i]==' ')//可能有多个空格
            {
                i ++;
            }
            if(word[i] == '.')
            {
                printf("
    ");
                break;
            }
            count ++;
            i ++;
        }
        return 0;
    }

     //测试样例:

    //It's great to see you here.
    //4 5 2 3 3 4
    // It's g ~reat t**(o s^%7e+ you here .//great之间隔Table键
    // 4 7 5 6 3 4

  • 相关阅读:
    POJ
    POJ
    HDU-3374 String Problem (最小最大表示法)
    HDU-2328 Corporate Identity (暴力)
    HDU-1238 Substrings (kmp)
    kmp处理题型总结
    Numpy用户指南
    Docker 容器连接
    Docker 镜像使用
    docker容器的使用
  • 原文地址:https://www.cnblogs.com/emptyCoder/p/5152063.html
Copyright © 2011-2022 走看看