当前位置: 代码迷 >> 综合 >> CodeForces - 358B Dima and Text Messages(字符串,水)
  详细解决方案

CodeForces - 358B Dima and Text Messages(字符串,水)

热度:12   发布时间:2023-11-08 16:04:13.0

B. Dima and Text Messages

思路很简单,字符串匹配,顺序扫一遍,o(n)的算法,居然TLE~~~~

原因居然是strlen

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define For(a,b) for(int a=0;a<b;a++)
#define mem(x) memset(x,0,sizeof(x))
#define Debug(x) cout<<"---> "<<x<<endl;
#define sf scanf
#define pf printf
int gcd(int a,int b){ return b>0?gcd(b,a%b):a;}
typedef long long ll;
typedef pair<int ,int > P;
//head
#define maxn 300100
string s,ss,ps;
int m,n,k;
int main(){cin>>n;ss="<3";for(int i=0;i<n;i++){cin>>s;ss+=s;ss+="<3";}m=ss.size();cin>>ps;int len=ps.length();//ss是输入的字符串,ps是匹配的字符串 for(int i=0;i<len;i++){if(ss[k]==ps[i]){k++;}if(k>=m){           //匹配结束 cout<<"yes"<<endl;return 0; }}cout<<"no"<<endl;return 0;
}
  相关解决方案