字符串最后一个单词长度

来源:互联网 发布:阿里云装mysql数据库 编辑:程序博客网 时间:2024/04/29 23:35
#include<iostream>
using namespace std;
#include<string>
int main()
{
 string str;
 while(getline(cin,str))
  {


  int len=str.size();
  int p=0;
  int q=0;
  while(p<len)
      {
     if(str[p]==' ')
       {    ++p;
         if(p<len)
           q=p;
       }
     else p++;
       }
   int count=0;
   while(q<len)
   { 
  if((str[q]>='A'&&str[q]<='Z')||(str[q]>='a'&&str[q]<='z'))
                      ++count;
     q++;
   }
       cout<<count<<endl;
 // system("pause");
  }
    return 0;
  
}
0 0
原创粉丝点击