917. 仅仅反转字母
class Solution {
public:
bool IsLetter(char ch)//判断是否是字母//
{
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
return true;
else
return false;
}
string reverseOnlyLetters(string s) {
if(s.empty())//判空,若是空,则不进行下面的操作//
return s;
size_t begin=0,end=s.size()-1;
while(begin
字符串最后一个单词的长度_牛客题霸_牛客网 (nowcoder.com)
#include
#include
using namespace std;
int main()
{
string s ;
getline(cin,s);//防止字符串中间有空格导致读取中断//
size_t pos=s.rfind(' ');//逆序找第一个空格//
if(pos!=string::npos)//返回第一个空格对应的下标不等于string最大长度//
{
cout<