zoukankan      html  css  js  c++  java
  • 1055: 输入字符串以及输出

    1055: 输入字符串以及输出

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 1905  解决: 1192
    [提交][状态][讨论版][命题人:外部导入]

    题目描述

    编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。

    输入

    一行字符串

    输出

    统计数据,4个数字,空格分开。

    样例输入

    !@#$%^QWERT    1234567

    样例输出

    5 7 4 6 

    #include<stdio.h>
    #include<string.h>
    void tongji(char str[], int a[])
    {
        int len = strlen(str);
        int i;
        //for(i = 0; i < 4; ++i)
           // a[i] = 0;
        memset(a, 0, 4 * sizeof(int));
        for(i = 0; i < len; ++i)
        {
            if((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
            {
                a[0]++;
            }
            else if(str[i] >= '0' & str[i] <= '9')
            {
                a[1]++;
            }
            else if(str[i] == ' ')
            {
                a[2]++;
            }
            else
                a[3]++;
        }
    }
    int main()
    {
        char str[100];
        int i,a[4];
        gets(str);
        tongji(str,a);
        for(i=0; i<4; i++)
            printf("%d ",a[i]);
        printf("
    ");
        return 0;
    }
    

      

     
  • 相关阅读:
    G
    ZOJ 3782
    23.内存池
    22.boost图模板
    21.boost Ford最短路径算法(效率低)
    20.boost dijkstra最短路径算法
    19.boost A*算法
    18.boost 图的拓扑排序
    17.广度优先遍历bfs
    16.boost图深度优先遍历DFS
  • 原文地址:https://www.cnblogs.com/mjn1/p/9936904.html
Copyright © 2011-2022 走看看