• [YTU]_1055 (输入字符串以及输出)


    Description
    编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。
    Input
    一行字符串
    Output
    统计数据,4个数字,空格分开。
    Sample Input
    !@#$%^QWERT    1234567
    Sample Output
    5 7 4 6
    #include <iostream>
    using namespace std;
    void tongji(char*p,int *q)
    {
    (*(q+3))=(*(q+2))=(*(q+1))=*q=0;
        for(;*p!='';p++)
        {
            if((*p>='a'&&*p<='z')||(*p>='A'&&*p<='Z'))
                (*q)++;
            else if(*p>=48&&*p<=57)
                (*(q+1))++;
            else if(*p==' ')
                (*(q+2))++;
            else
                (*(q+3))++;
        }
    }
    int main()
    {
        char str[100];
        int i,a[4]={0};
        cin.getline(str,99);
        tongji(str,a);
        for(i=0; i<4; i++)
            cout<<a[i]<<" ";
        cout<<endl;
        return 0;
    }
    #include <iostream>
    using namespace std;
    void tongji(char *p,int *aa)
    {
        int m=0,n=0,j=0,k=0;
        for(int i=0;*(p+i)!='';i++)
        {
            if((*(p+i)>='a'&&*(p+i)<='z')||(*(p+i)>='A'&&*(p+i)<='Z'))
               {
                m++;
                *aa=m;
               }
                else if(*(p+i)>='0'&&*(p+i)<='9')
               {
                n++;
                aa[1]=n;
               }
                else if(*(p+i)==' ')
                 {
                    j++;
                    aa[2]=j;
                 }
                else
                    {k++;
                    aa[3]=k;
                    }
        }
    }
    int main()
    {
      char str[100];
      int i,a[4];
      cin.getline(str,99);
      tongji(str,a);
      for(i=0;i<4;i++)
          cout<<a[i]<<' ';
          cout<<endl;
          return 0;
    }
    

    
    
    
    
  • 相关阅读:
    机器学习-liuyubobobo(慕课网)
    python进阶 廖雪峰(慕课网)
    ajax 报0错误
    nav破解
    thinkphp5--关于多条件查询的分页处理问题
    JS/JQuery获取当前元素的上一个/下一个兄弟级元素等元素的方法
    linux 批量删除文件
    Linux下which命令使用详解(转)
    thinkphp5和nginx不得不说的故事
    Git基本操作和使用
  • 原文地址:https://www.cnblogs.com/sxy201658506207/p/7586389.html
Copyright © 2020-2023  润新知