相关疑难解决方法(0)

继承和覆盖std :: string的函数?

既然std::string实际上是typedef模板类,我怎么能覆盖呢?我想制作一个std::string能返回正确长度的UTF-8 .

c++ unicode utf-8 character-encoding

12
推荐指数
2
解决办法
5398
查看次数

检查字符串是否是回文

可能重复:
查找给定字符串是否为回文结构或不是回文结构

我需要创建一个程序,允许用户输入一个字符串,我的程序将检查他们输入的字符串是否是回文(可以向前读取相同的单词).

c++

10
推荐指数
3
解决办法
15万
查看次数

C++ Palindrome查找器优化

我一直在用C++写一个回文查找器,我已经成功地编写了一个......至少可以说是基本的.

我只想增加程序的速度,现在需要大约1m 5s才能使用我拥有的功能在1500字的单词列表上运行palindromes/2字回文测试.我想尝试在更大的文件上运行它,但却看不到我可以进一步优化的位置?

任何帮助将不胜感激:PS这不是为了学校,只是为了休闲.

#include <iostream>
#include <ostream>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;

bool isPal(string);

int main() {

vector<string> sVec;
vector<string> sWords;
vector<string> sTwoWords1;
vector<string> sTwoWords2;
char myfile[256]="/home/Damien/Test.txt";
ifstream fin;
string str;
fin.open(myfile);
    if(!fin){ 
        cout << "fin failed";
        return 0;
    }
while(fin){

    fin >> str;
    sWords.push_back(str);
    if(!fin){
        break;
    }
    if(isPal(str)){
      sVec.push_back(str);
    }
    else{
        getline(fin, str);
    }
}
    reverse(sVec.begin(), sVec.end());
    for(int i =0; i < sVec.size(); i++){
        cout << sVec[i] << " is a Palindrome " <<endl; …
Run Code Online (Sandbox Code Playgroud)

c++ function

4
推荐指数
1
解决办法
1709
查看次数

标签 统计

c++ ×3

character-encoding ×1

function ×1

unicode ×1

utf-8 ×1