434. Number of Segments in a String
来源:互联网 发布:网络大电影编剧价格 编辑:程序博客网 时间:2024/06/06 01:24
题目:
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.
Please note that the string does not contain any non-printable characters.
Example:
Input: "Hello, my name is John"Output: 5stoke函数使用,返回为 char*,参数列表,第一个为待分割的的char* 第一次写了之后后面可以置为NULL,自动分割剩下的字符串,第二个为分割的字符符号。
string 转char*
1.一种是string s,s.c_str();char *p=str.c_str();
2.第二种是 !!!!!!!
string str="abc";
char *p=str.data();%这行应更正为char*p=(char*)str.data();,引自贴内网友的回复
3.
3. copy
比如
string str="hello";
char p[40];
str.copy(p,5,0); //这里5,代表复制几个字符,0代表复制的位置
*(p+5)='\0'; //要手动加上结束符
class Solution {public: int countSegments(string s) { char * m =(char*)s.data(); int count = 0; const char * split = " "; char * p; p = strtok(m,split); while(p!=NULL) { count++; p = strtok(NULL,split); } return count; }};
阅读全文
0 0
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String*
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434. Number of Segments in a String
- 434.Number of Segments in a String(String-Easy)
- String:434. Number of Segments in a String
- Leetcode434. Number of Segments in a String
- Metasploit实战-利用木马获取他人教务管理系统的账号,密码
- java使用HttpClient发送http请求
- WebView 加载html5 报错
- (一). 框架基础认识(路由,CURD)
- Android_TextView属性XML详解
- 434. Number of Segments in a String
- 70. Climbing Stairs (dp)
- 【算法】删除相邻的重复元素
- 上传文件如何在打开对话框中只显示指定后缀的文件
- freemarker 数字过长去掉逗号
- Android 去掉窗口标题和程序全屏
- java提高篇(十九)-----数组之二
- js复制兼容android,ios,pc
- Android模拟器DPAD not enabled in avd 启用