可爱STL,嘟嘟嘟!

· · 题解

可以当作一个简单的队列题来做。

也有可能我太蒟蒻了,一眼想到了队列。

题目还是很好理解的。

主要思路

AC code

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
#define fst ios::sync_with_stdio ( false ) ; cin.tie (0) ; cout.tie (0) ;

using namespace std ;

const int Mod = 998244353 ;
const int N = 5e6 + 7 ;
const int M = 1e5 ;
string o , p ;
queue<char > s , s1 ;
signed main ()
{
    fst ;
    cin >> o >> p ;
    for (int i = 0 ; i < o.size() ; i ++)
    {
        s.push(o[i]) ;
    }
    for (int i = 0 ; i < p.size() ; i ++)
    {
        s1.push(p[i]) ;
    }
    int ans = 0 ;
    while (!s1.empty())
    {
        if (s.empty())
        {
            break ;
        }
        if (s.front() != s1.front())
        {
            s1.pop() ;
        }
        else
        {
            s.pop() ;
            s1.pop() ;
        }
        ans ++ ;
    }
    if (!s.empty())
    {
        ans = -1 ;
    }
    cout << ans ;
    return 0 ;
}