2017.10.31 LeetCode - 58. Length of Last Word 【ctype.h的简单运用与总结】
2017-10-31 19:47
561 查看
58. Length of Last Word
Description
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.
Note: A word is defined as a character sequence consists of non-space characters only.
For example,
Given s = “Hello World”,
return 5.
题意: 返回最后一个单词的长度
分析: 虽然是水题,但还是挖了不少好东西呀,一些ctype头文件里的其他的常见函数总结在下面
参考函数
class Solution { public: int lengthOfLastWord(string s) { if(s.size() == 0) return 0; int res = 0; int len = s.size(); bool flg = false; for(int i = len-1;i >= 0;i--) { if(isalpha(s[i])) { while(isalpha(s[i--])) { res++; }break; } } return res; } };
小节
@函数名称: isalpha函数原型: int isalpha(int ch);
函数功能: 检查ch是否是字母.
函数返回: 1是字母返回 ,否则返回 0.
@函数名称: iscntrl
函数原型: int iscntrl(int ch);
函数功能: 检查ch是否控制字符(其ASCII码在0和0x1F之间,数值为 0-31).
函数返回: 是返回 1,否则返回 0.
@函数名称: isdigit
函数原型: int isdigit(int ch);
函数功能: 检查ch是否是数字(0-9)
函数返回: 是返回1,否则返回0
@函数名称: isgraph
函数原型: int isgraph(int ch);
函数功能: 检查ch是否可显示字符(其ASCII码在ox21到ox7E之间),不包括空格
函数返回: 是返回1,否则返回0
@函数名称: islower
函数原型: int islower(int ch);
函数功能: 检查ch是否小写字母 (a-z)
函数返回: 是返回1,否则返回0
@函数名称: tolower
函数原型: int tolower(int ch);
函数功能: 将ch字符转换为小写字母
函数返回: 返回ch所代表的字符的小写字母
@函数名称: toupper
函数原型: int toupper(int ch);
函数功能: 将ch字符转换成大写字母
函数返回: 与ch相应的大写字母
@函数名称: isalnum
函数原型: int isalnum(int ch);
函数功能: 检查ch是否是字母或数字
函数返回: 是字母或数字返回1,否则返回0
@函数名称: isprint
函数原型: int isprint(int ch);
函数功能: 检查ch是否是可打印字符(包括空格),其ASCII码在ox20到ox7E之间
函数返回: 是返回1,否则返回0
@函数名称: ispunct
函数原型: int ispunct(int ch);
函数功能: 检查ch是否是标点字符(不包括空格),即除字母,数字和空格以外的所有可打印字符
函数返回: 是返回1,否则返回0
@函数名称: isspace
函数原型: int isspace(int ch);
函数功能: 检查ch是否是空格符和跳格符(控制字符)或换行符
函数返回: 是返回1,否则返回0
@函数名称: isupper
函数原型: int isupper(int ch);
函数功能: 检查ch是否是大写字母(A-Z)
函数返回: 是返回1,否则返回0
@函数名称: isxdigit
函数原型: int isxdigit(int ch);
函数功能: 检查ch是否是一个16进制数学字符(即0-9,或A-F,或a-f)
函数返回: 是返回 1,否则返回0
@函数名称: isascii
函数原型: int isascii(int ch)
函数功能: 测试参数是否是ASCII码0-127
函数返回: 非零-是,0-不是
参数说明: ch-被测参数
相关文章推荐
- leetcode-java-58. Length of Last Word
- Leetcode 58. Length of Last Word
- Leetcode 58. Length of Last Word
- [LeetCode]--58. Length of Last Word
- LeetCode 58. Length of Last Word
- [leetcode] 58. Length of Last Word 解题报告
- Leetcode 58. Length of Last Word
- [LeetCode]58. Length of Last Word
- 【leetcode】58. Length of Last Word
- leetcode 58. Length of Last Word
- leetcode: 58. Length of Last Word
- leetcode -58. Length of Last Word
- [LeetCode] 58. Length of Last Word
- LeetCode 58. Length of Last Word
- leetcode题解-58. Length of Last Word
- [LeetCode]58. Length of Last Word
- Leetcode:58. Length of Last Word(JAVA)
- LeetCode 58. Length of Last Word
- LeetCode --- 58. Length of Last Word
- LeetCode 58. Length of Last Word