字符串最後一個單詞的長度-簡單題

#include<iostream>
using namespace std;
 
int findLastNumLength(char *s,int le)
{
 if(s==NULL||le<=0)
  return 0;
 int l=0;
 char *endl=s;
 while(*endl)
  endl++;
 endl--;
 while(*endl==' ')
  endl--;
 while(le)
 {
  if(*endl!=' ')
  {
   l++;
   endl--;
  }
  le--;
 }
 return l;
}
 
int main()
{
 char s[100];
 cin.getline(s,100);
 cout<<findLastNumLength(s,strlen(s));
 system("pause");
 return 0;
}
相關文章
相關標籤/搜索