莫问纷飞


私信TA

用户名:uq_94607330609

访问量:128

签 名:

等  级
排  名 35617
经  验 388
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

简洁:找规律
浏览:19

解题思路:

比较两个字符,若这两个字符相等,那么不必操作,若这两个字符不等,则比较后面两个字符串的后一位,如也相等,则替换,否则,删除,同时操作数加1。

参考代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()

{

    string a,b;

    cin>>a>>b;

    int cnt=0,j=0;

    string::iterator it,itb;

    for(it=a.begin();it<a.end();it++)

    {

        if(*it==b[j])

            j++;

        else if(*it!=b[j]&&*(it+1)==b[j])

            {

                *it=b[j];

                cnt++;

            }

        else

        {

            a.erase(it);

            cnt++;

        }

    }

      cout<<cnt<<endl;

  

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区