讯飞笔试统计字符串的题

#include<iostream>
#include<string>
#include<vector>
#include<sstream>
using namespace std;

int main(void) {

	string str;
	cin >> str;
	stringstream cinstr(str);
	string ch;
	string search("0123456789");
	vector<char> vec;
	int count = 0;
	while (getline(cinstr,ch,',')) {
		
		string::size_type pos=0;
		if (pos = ch.find_first_not_of(search, pos) == string::npos) {
			int a = ch[0] - '0';
			int b = ch[ch.size() - 1] - '0';
			if (a + b > 8) {
				count++;
			}
		}
		else {
			continue;
		}
	}
	cout << count << endl;

	return 0;
}

#科大讯飞##笔试题目#
全部评论
欢迎讨论
点赞 回复 分享
发布于 2019-09-12 11:55
    输入一个字符串,字符串中包含多个子串,每个子串之间用一个或多个逗号“,”隔开,子串内容可能是纯数字串、纯英文单词或者英文字母、数字、符号混合的字符串(字符串长度100以内),统计这些子串中所有首位和末位数字之和大于8的纯数字串的个数,要求时间复杂度小于等于O(n)。     输入:     hello,79,1.9,are,09,there     输出:     2
点赞 回复 分享
发布于 2019-09-12 12:01
这题不难😁不过你写的比我时间复杂度低
点赞 回复 分享
发布于 2019-09-12 12:43

相关推荐

评论
4
6
分享

创作者周榜

更多
牛客网
牛客企业服务