zoukankan      html  css  js  c++  java
  • 阿里笔试第一题

     在S中查找T的序列,对于当前S[i],如果不等于T[j],那么让i+1,最后判断下-1的情况就ok了
     
    /// file :: 2jjalloc.h
    #ifndef _JJALLOC_
    #define _JJALLOC_
    
    #include<new>/// for placement new
    #include<cstddef>/// for ptrdiff_t,size_t;
    #include<cstdlib>/// for exit()
    #include<climits>/// for unit_max
    #include<iostream>///for cerr
    
    #endif
    namespace JJ
    {
        template <class T>
        inline T* _allocate(ptrdiff_t siz,T *) {
            std::set_new_handler(0);
            T* tmp = (T*)(::operator new ((size_t)(siz*(sizeof(T)))));
            if(!tmp){
                std::cerr<<"out of merry"<<std::endl;
                exit(1);
            }
            return tmp;
        }
        template <class T>
        inline void _delallocate(T*buffer){
            ::operator delete(buffer);
        }
        template <class T>
        inline void _destory(T* tmp){
               tmp->~T();
        }
        template <class T1,class T2>
        inline void _construct(T1 *p,const T2& val){
             new (p) T1(val);
        }
    }
    
    
    #include<bits/stdc++.h>
    using namespace std;
    map<char,int>mp;
    int main() {
        string str1,str2;
        cin>>str1>>str2;
        int i=0,j=0;
        for(i=0;i<str1.size();++i){
            if(str1[i]==str2[j])++j;
            else mp[str1[i]]++;
        }
        int ans=str1.size()-j;
        for(j;j<str1.size();++j){
            mp[str2[j]]--;
            if(mp[str2[j]]<0)ans=-1;
        }
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    索引
    varnish它是一款高性能的http缓存服务器
    前端性能优化浅谈
    锁机制-SQL Server 数据库
    NET Core中NuGet包
    “干掉” if...else
    混搭.NET技术
    MONO x64 amd_x64
    跨平台移动开发UI语言 -XAML
    使用LinqToExcel读取Excel
  • 原文地址:https://www.cnblogs.com/DreamKill/p/12579683.html
Copyright © 2011-2022 走看看