A. Single Wildcard Pattern Matching
http://codeforces.com/contest/1023/problem/A
题解:记录*的位置,然后判断前后位置是否相同
#include <bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
int n,m,pos=-1;
scanf("%d%d",&n,&m);
cin>>a>>b;
for (int i=0;i<a.length();i++){
if (a[i]=='*'){
pos=i;
break;
}
}
if (pos==-1){
if (a==b)
puts("YES");
else
puts("NO");
}
else if (n>m+1){
puts("NO");
}
else {
for(int i=0;i<pos;i++){
if(a[i]!=b[i]){
puts("NO");
return 0;
}
}
for(int i=n-1;i>pos;i--){
if(a[i]!=b[i-n+m]){
puts("NO");
return 0;
}
}
puts("YES");
}
return 0;
}
B. Pair of Toys
http://codeforces.com/contest/1023/problem/B
题解:思维题,分情况讨论
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n,k,i,j,s;
cin>>n>>k;
if(n<k/2) cout<<"0"<<endl;
else {
if(n>=k)
n=k-1;
cout<<n-k/2<<endl;
}
return 0;
}
C. Bracket Subsequence
http://codeforces.com/contest/1023/problem/C
解题:存储满足条件的(和)
#include<bits/stdc++.h>
using namespace std;
char s[200005];
int main(){
int k,n,a,b;
while(~scanf("%d%d",&n,&k)) {
a=0,b=0;
scanf("%s",s);
int len=strlen(s);
for(int i=0;i<len;i++){
if(s[i]=='('&&a<k/2){
a++;
printf("(");
}
else if(s[i]==')'&&b<k/2){
b++;
printf(")");
}
}
printf("\n");
}
return 0;
}