#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<string> splitEx(const string& src, string separate_character)
{
vector<string> strs;

int separate_characterLen = separate_character.size();//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符
int lastPosition = 0, index = -1;
while (-1 != (index = src.find(separate_character, lastPosition)))
{
strs.push_back(src.substr(lastPosition, index - lastPosition));
lastPosition = index + separate_characterLen;
}
string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容
if (!lastString.empty())
strs.push_back(lastString);//如果最后一个分隔符后还有内容就入队
return strs;
}

int main()
{
/*
string s;
string sum;
while (cin >> s){
sum += s + " ";
if (cin.get() == '\n')
break;
}
cout << sum << endl;
*/
int tpp = 1;
string str;
do{
string s;
string temp;
cout << "输入一行字符串:\n";
while (cin >> s){
temp += s + " ";
if (cin.get() == '\n')
break;
}
cout << "继续输入请按1";
cout << temp << endl;
str = temp;
cin >> tpp;

} while (tpp==1);

//string str;
/*
int count;//单词个数
int i, j;
*/

//cout << "输入一行字符串:\n";
//getline(cin, str);

/*
for (count = 0, j = str.size(), i = 0; i<j;)
{
while (str[i] == ' '&&i<j) i++;
if (i<j) count++;
while (str[i] != ' '&&i<j) i++;
}
cout << "j=" << str.size() << endl;
cout << "输入的字符串为:\n" << str << endl;
cout << "字符串中包含的单词数为:" << count << endl;
*/

string del = " ";
vector<string> strs = splitEx(str, del);
//cout << "strsSize=" << strs.size() << endl;
cout << "输入的字符串为:\n" << str << endl;
cout << "字符串中包含的单词数为:" << strs.size() << endl;
//int a,b,c,d;
unsigned int i = strs.size()-1;
while (i >=0)
//for (unsigned int i = 0; i < strs.size(); i++)
{
int j = 1;
int a = atoi(strs[i].c_str());
int b = atoi(strs[i-1].c_str());
int c = atoi(strs[i - 2].c_str());
int d = atoi(strs[i-3].c_str());
int cc = atoi(strs[j+2].c_str());
//cout <<b+1 << endl;
if (a == b && c == d){
cout << "yes" << endl;
break;
}

else
{
cout << "no" << endl;
break;
}
//i -= 3;
}

cout << endl;
system("pause");
return 0;

}

c++关于字符串的读入和截取的更多相关文章

  1. php字符串标点等字符截取不乱吗 封装方法

    方法一: /**   +----------------------------------------------------------  * 功能:字符串截取指定长度  * leo.li hen ...

  2. [转]Python 字符串操作实现代码(截取/替换/查找/分割)

    原文地址:http://www.jb51.net/article/38102.htm ps:好久没更新python代码了,这次用到了字符串,转来看看 Python 截取字符串使用 变量[头下标:尾下标 ...

  3. 字符串长度计算、截取、url参数获取、计算百分比、时间戳格式化

    1.中英混合文字字符截取 //中文长度截取计算,可取中英混合,个数向上取整,精确度1个英文字符误差,一个英文算一个字符,一个汉字算一个字符. //sub("中文zlsd",1) - ...

  4. go语言字符串的连接和截取

    字符串的连接: https://studygolang.com/articles/12281?fr=sidebar 字符串的截取: https://studygolang.com/articles/9 ...

  5. javascript 字符串的连接和截取

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. PHP针对中英文混合字符串长度判断及截取方法

    PHP自带的函数如strlen().mb_strlen()都是通过计算字符串所占字节数来统计字符串长度的,一个英文字符占1字节.例: $enStr = 'Hello,China!'; echo str ...

  7. UTF8字符串在lua的截取和字数统计【转载】

    转载自:GitHub:pangliang/pangliang.github.com 需求 按字面个数来截取 函数(字符串, 开始位置, 截取长度) utf8sub(,) = 好1世界哈 utf8sub ...

  8. StringsUtil字符串工具类---灵活截取

    package com.js.ai.modules.pointwall.interfac; import javax.print.attribute.standard.MediaName; publi ...

  9. js判断中文字符串长度和js截取中文字符串

    //获取字符串长度String.prototype.strLen = function() { var len = 0; for (var i = 0; i < this.length; i++ ...

随机推荐

  1. Find Duplicate File in System

    Given a list of directory info including directory path, and all the files with contents in this dir ...

  2. JDK1.8 新特性(全)

    原文链接:https://blog.csdn.net/qq_29411737/article/details/80835658

  3. flask 接收参数小坑

    前后端分离: 1.get方式: items = dict(request.args.items()) app_name = items["app_name"].strip() 或 ...

  4. 牛客 158F 青蛙 (贪心)

    显然存在一个最优解满足所有青蛙在连续的一段, 每次由最左侧青蛙跳向下一格. 然后二分或者双指针即可求出答案. #include <iostream> #include <sstrea ...

  5. 高性能MySQL3_笔记1_Mysql的架构与历史

    第一层:连接处理.授权认证.安全 第二层:mysql的核心功能,包括查询解析.分析.优化.缓存以及所有的内置函数(例如日期.加密.数学函数), 所有跨存储引擎的功能都在这一层实现:存储过程.触发器.视 ...

  6. 【原创】大叔问题定位分享(35)spring中session失效时间

    spring项目中将sessionid对应的cookie过期时间设置很长,但是实际session还是在半个小时后失效,跟了一下代码,spring中session实现接口为 org.springfram ...

  7. ubuntu 编译zbar 静态库

    wget http://downloads.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.gz tar -zvxf zbar-0.10.ta ...

  8. Presto基础知识

    背景 MapReduce不能满足大数据快速实时adhoc查询计算的性能要求. Facebook的数据仓库存储在少量大型Hadoop/HDFS集群.Hive是Facebook在几年前专为Hadoop打造 ...

  9. python入坑级

    pycharm设置 pycharm设置自动换行的方法 只对当前文件有效的操作:菜单栏->View -> Active Editor -> Use Soft Wraps: 如果想对所有 ...

  10. Delphi 图形组件(Shape)

    樊伟胜