lsfdd


私信TA

用户名:lsfdd

访问量:422

签 名:

等  级
排  名 32693
经  验 421
参赛次数 0
文章发表 1
年  龄 0
在职情况 学生
学  校 国防科大
专  业

  自我简介:

TA的其他文章

c++,cin.get()解法
浏览:187

解题思路:
cin.get()读到行的最后一个,但是不读入回车,因此,通过读到null终止循环。
注意事项:

参考代码:

#include<iostream>


#include<string>

using namespace std;

int main()

{

   char s[201];

   cin.get(s,201);

   int i=0;

   int a=0;

   int b=0;

   int c=0;

   int d=0;

   while(s[i]!=NULL)

   {

       if(s[i]>='a'&&s[i]<='z')

            a++;

        else if(s[i]>='A'&&s[i]<='Z')

            a++;

       else if(s[i]==' ')

        b++;

       else if(int(s[i])>=48&&int(s[i])<=57)

        c++;

       else

        d++;

    i++;

   }

   cout<<a<<' '<<c<<' '<<b<<' '<<d;

}


 

0.0分

0 人评分

  评论区