oj:回文字符串处理
来源:互联网 发布:深圳有名的公司 知乎 编辑:程序博客网 时间:2024/05/18 00:55
思路:首先使用string 的s.insert()插入,然后使用反转函数reverse(),最后比较是否相等
#include <iostream>#include <string>using namespace std;int main(){ string str1,str2; while (cin >> str1 >>str2) { size_t pos=0,count= 0; while (pos <= str1.size()) { string tmp = str1; tmp.insert(pos++, str2); // 指定位置插入 string _tmp = tmp; reverse(_tmp.begin(), _tmp.end()); //然后反转字符串 if (tmp.compare(_tmp) == 0) //比较与原串是否相等 count++; } cout << count << endl; } system("pause"); return 0;}
string的成员函数insert有以下多种重载:
string &insert(int p0, const char *s);——在p0位置插入字符串s
string &insert(int p0, const char *s, int n);——在p0位置插入字符串s的前n个字符
string &insert(int p0,const string &s);——在p0位置插入字符串s
string &insert(int p0,const string &s, int pos, int n);——在p0位置插入字符串s从pos开始的连续n个字符
string &insert(int p0, int n, char c);//在p0处插入n个字符c
iterator insert(iterator it, char c);//在it处插入字符c,返回插入后迭代器的位置
void insert(iterator it, const_iterator first, const_iteratorlast);//在it处插入从first开始至last-1的所有字符
void insert(iterator it, int n, char c);//在it处插入n个字符c
0 0
- oj:回文字符串处理
- 南阳oj 回文字符串
- UVa OJ 401回文字符串
- 字符串处理------回文判断
- [字符串处理]回文串
- 华为oj--字符串截取(最长回文字符串)
- 九度OJ 1252:回文子串 (字符串处理、DP)
- OJ-----字符串合并处理
- 九度OJ 题目1192:回文字符串
- 九度OJ 题目1192:回文字符串
- 南阳 oj 动态规划 回文字符串
- 九度OJ 1192:回文字符串
- 【九度OJ】1192:回文字符串
- Manacher算法处理字符串回文
- Manacher算法处理字符串回文
- 字符串专题:Manacher算法处理字符串回文
- 华为oj 字符串合并处理
- 华为oj字符串合并处理
- 2016.8.6 做题汇报
- leetcode 41. First Missing Positive
- 跟我一起写Makefile(10)--- 变量(嵌套变量+追加变量+overrid+多行变量+环境变量+目标变量+模式变量)
- iOS序列帧动画
- JDK8 十大新特性详解
- oj:回文字符串处理
- 排序检索-123 quick searching
- java中常用注解
- AS汇编器源码剖析-第1章-Arm操作码
- 本地广播LocalBroadcastManager与Android.support.v4.jar导入
- ACM博弈论小结
- CodeForces 148D Bag of mice (经典概率dp)
- 对HTTP请求的Get和Post的一些理解
- python模块之mysql模块MySQLdb