#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. kafka原理和操作

    参考: 原理: https://www.cnblogs.com/yinzhengjie/p/9780976.html 常用配置参数: https://www.cnblogs.com/yinzhengj ...

  2. [转帖]Zookeeper vs etcd vs Consul比较

    Zookeeper vs etcd vs Consul比较 https://it.baiked.com/consul/2341.html 需要转型 加强学习. 如果使用预定义的端口,服务越多,发生冲突 ...

  3. Python +requests 关于post请求返回报错

    python+request 发送post请求:msg返回"Content type 'application/octet-stream' not supported" 一.问题源 ...

  4. C++入门基础知识(二)

    一:引用 概念:是给一个已经存在的变量取一个别名,编译器不会为引用变量开辟内存空间,它和引用的变量公用一块内存空间. 例如: 类型& 引用变量名(对象名)= 引用实体 int& a = ...

  5. java lesson14Homework

    /** * 1. 本程序找出字符串数组 String[] arr = {“welcome”, “china”, “hi”, “congratulation”, “great”} 中的长度最大的元素,并 ...

  6. IIS--解决64位系统IIS网站发布出现未能加载文件或程序集“...”或它的某一个依赖项。试图加载

    解决64位系统IIS网站发布出现未能加载文件或程序集“...”或它的某一个依赖项.试图加载 ASP.NET MVC 项目发布的在本地IIS后,启动网站出现未能加载文件或程序集“…”或它的某一个依赖项. ...

  7. opencv 模板匹配, 已解决模板过大程序不工作的bug

    #include <opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv ...

  8. vue编程式导航,命名路由

    //使用 window.location.href 的形式,叫做 编程式导航 绑定事件的形式 <template> <div class="goods-item" ...

  9. 如何将spring源码导入到eclipse中

    如何将spring源码导入到eclipse中 1. 下载spring源码  可以在github官网中找到spring源码来下载,或者直接通过git下载,是一样的,这里演示 直接在github网站下载, ...

  10. 跨平台编译ceres for Android

    折腾了几乎一天,记录一下. 最大的坑是官网给出的 1.进入ceres源代码目录下的jni目录 2.EIGEN_PATH="指向eigen库目录,即包含EIGEN文件夹的那个文件夹” ndk- ...