Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值