码迷,mamicode.com
首页 > 其他好文 > 详细

B. Obtaining the String(模拟)

时间:2019-04-13 21:44:45      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:开始   color   nbsp   ace   数组   思路   cst   原因   str   

比较水的模拟

思路:就是模拟题意

注意:把数组开大点,开始wa了几次就是这个原因

#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string a, b;
int aa[100000], t, n;
bool flag1;

int main(){
    cin>>n;
    cin>>a>>b;
    int p=0, q=0;
    while(q<n){
        bool flag=0;
        while(q<n&&a[p]==b[q]){++p; ++q;}
        while(p<n&&a[p]!=b[q]){++p; flag=1;}
        if(flag&&p==n){flag1=1; break;}
        for(int i=p;i>q;--i){
            swap(a[i], a[i-1]);   aa[t++]=i;
        }
        p=q;
    }
    if(flag1)cout<<-1<<endl;
    else {
        cout<<t<<endl;
        for(int i=0;i<t;++i)
            cout<<aa[i]<<" ";
        cout<<endl;
    }

}

 

B. Obtaining the String(模拟)

标签:开始   color   nbsp   ace   数组   思路   cst   原因   str   

原文地址:https://www.cnblogs.com/ALINGMAOMAO/p/10702931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!