1.两种情况,一种是没有结束标点的时候,一种是有的时候,用标准库STL::string来实现
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
getline(cin,str);
string::size_type pos=str.rfind(' ');
string::size_type length=str.length();
if('a'<=str[length-1] && str[length-1]>= 'z')
{
cout<<length-1-pos<<endl;
}
if('A'<=str[length-1] && str[length-1]>= 'Z')
{
cout<<length-1-pos<<endl;
}
else
cout<<length-2-pos<<endl;
return 0;
}