c++sting类 在字符串中找相同的字符 并且把他删除

#include<iostream>
#include<string>

int main()
{
    string str=;  //十个字符串
    string::iterator it;   //stirng 迭代
    int index=str.find("\\");
    int x=0;
    while(inedx!=-1)
    {
        if((index-1)==0)  //前面的减去后面的是1那么就是相同
        {
            it=str.begin();
            cout<<"找到相同的了"
            str.erase(it+index);
        }
        x=index;
        index=str.find("\\",index+1);
    }
    
   return 0;
}
时间: 2024-08-25 10:36:38

c++sting类 在字符串中找相同的字符 并且把他删除的相关文章

【C语言】自己编写程序实现strchr函数。即在给定字符串中找特定的字符并返回该处指针。

<pre name="code" class="cpp">//自己编写程序实现strchr函数.即在给定字符串中找特定的字符并返回该处指针. #include <stdio.h> char * my_strchr(char const *str,int ch) { while(*str!='\0') { if(*str!=ch) str++; else return str; } printf("未找到该字符\n"); r

【C语言】自己编写程序实现strrchr函数,即在给定字符串中找特定的字符并返回最后出现的位置

//自己编写程序实现strrchr函数,即在给定字符串中找特定的字符并返回最后出现的位置 #include <stdio.h> #include <string.h> char * my_strrchr(char const *str,int ch) { int count=0; while(*str!='\0') { count++; str++; } str--; while(count) { if(*str!=ch) { str--; count--; } else retu

【c语言】第一个只出现一次的字符题目:在字符串中找出第一个只出现一次的字符

// 第一个只出现一次的字符题目:在字符串中找出第一个只出现一次的字符. // 如输入"abaccdeff",则输出'b'. #include <stdio.h> #include <string.h> char find_one(char *str) { int a[256]; int len = strlen(str); int i = 0; memset(a, 0, sizeof(a)); for (i = 0; i<len; i++) { a[st

在字符串中找出第一个只出现一次的字符

题目: 在字符串中找出第一个只出现一次的字符.如输入"abaccdeff",则输出'b'. 题目分析: 对于在字符串中找出第一个出现一次的字符,联系ASCII码表,能够得到有256中不同的字符,可以利用字符的编码,将每个字符的编码作为数组的下表,建立一个有256个元素的数组arr[256],将数组中的每一个元素对应统计字符的个数,从字符串的第一个字符进行遍历,遇到一个字符给对应的数组元素加1,当数组中的其中一个元素变到2,则输出这个元素所对应的数组下表,即就是这个字符的ASCII码.

在字符串中找出连续最长的数字串 在字符串中找出连续最长的数字串,并把这个串的长度返回

写一个函数,它的原形是int continumax(char *outputstr,char *intputstr)功能:在字符串中找出连续最长的数字串,并把这个串的长度返回,并把这个最长数字串付给其中一个函数参数outputstr所指内存.例如:"abcd12345ed125ss123456789"的首地址传给intputstr后,函数将返回9, #include<iostream> using namespace std; int ContinueMax(char *

[LeetCode] 在一堆字符串中找出包含相同字符的 group的较快方法,题 Anagrams

题目: Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. class Solution { public: vector<string> anagrams(vector<string> &strs) { } }; 题意本身并不是很清晰,开始我的代码总是报Output Limit Exceeded,

在字符串中找出第一个只出现一次的字符。 如输入“abaccdeff”,则输出&#39;b&#39;。

在字符串中找出第一个只出现一次的字符. 如输入"abaccdeff",则输出'b'. 这个题加一些要求维度只能为n 代码如下: #include <stdio.h> #include <assert.h> char FLetter(char arry[],int len) {              int letterNumber[256] = {0};              int i = 0;              char *ch  = arr

[华为机试练习题]43.在字符串中找出连续最长的数字串

题目 描述: 请一个在字符串中找出连续最长的数字串,并把这个串的长度返回:如果存在长度相同的连续数字串,返回最后一个连续数字串: 注意:数字串只需要是数字组成的就可以,并不要求顺序,比如数字串"1234"的长度就小于数字串"1359055",如果没有数字,则返回空字符串("")而不是NULL! 样例输入 abcd12345ed125ss123058789 abcd12345ss54761 样例输出 输出123058789,函数返回值9 输出547

【C语言】在字符串中找出第一个只出现一次的字符。如输入“abaccdeff”,则输出’b’

//在字符串中找出第一个只出现一次的字符.如输入"abaccdeff",则输出'b' #include <stdio.h> #include <memory.h> char OneTime(char * str) { int data[256]; char *p = str; if (*p == '\0') return '\0'; memset(data, 0, sizeof(data)); while (*p ) { data[*p++]++; //把每种字