总结:
还是太菜,前三题都是简单题,但是我还是只做出来2题,第三题愣是没看懂题目,第一题在比赛的时候还被人hack了一次,好惨。。。。
题解:
A:
思路:可以用*将字符串变成两部分,分别比较,就可以,但是要注意没有*的情况(就是单纯比较两个字符串是否相等),还有以*开头或结尾的情况。。
代码:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <iomanip>
const int maxn=1e5;
using namespace std;
string a,b;
int main()
{
int w,t;
cin>>w>>t;
cin>>a>>b;
int len1=a.length(),len2=b.length();
if(len1-1>len2)
{
cout<<"NO"<<endl;
return 0;
}
int flag=0,bj=0;
string s1="",s2="";
for(int i=0;i<len1;i++)
{
if(a[i]=='*'){bj=1;continue;}
if(!bj)s1+=a[i];
if(bj)s2+=a[i];
}
if(!bj)
{
if(a==b)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
int l1=s1.length(),l2=s2.length();
for(int i=0;i<l1;i++)
{
if(s1[i]!=b[i]){flag=1;break;}
}
for(int i=0;i<l2;i++)
{
if(b[len2+i-l2]!=s2[i]){flag=1;break;}
}
if(flag)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return 0;
}
B:
思路:比较简单,就是用手推几个样例,就可以知道了
代码
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <iomanip>
const int maxn=1e5;
using namespace std;
long long a,b;
int main()
{
cin>>a>>b;
long long t=b/2;
long long tt=min(b-1,a);
if(tt<t)cout<<0<<endl;
else cout<<tt-t<<endl;
return 0;
}
C :
思路:这题题目是有点看不懂,好像是求一个子括号序列,满足长度为k,我们可以通过数组模拟每一位是(还是)。。。。
代码
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <iomanip>
const int maxn=2*1e5+10;
using namespace std;
int ans[maxn];
string s;
int main()
{
int a,b;
cin>>a>>b;
cin>>s;
b=b/2;
int cnt=0,sum=0,gs=0;
for(int i=0;i<a;i++)
{
if(s[i]=='(')
{
ans[cnt++]=1;
sum++;
gs++;
if(gs==b)break;
}
else
{
if(sum)
{
ans[cnt++]=2;
sum--;
}
}
}
while(sum)
{
ans[cnt++]=2;
sum--;
}
for(int i=0;i<cnt;i++)
if(ans[i]==1)putchar('(');else putchar(')');
return 0;
}