The 14th Zhejiang University Programming Contest D题&I题

这次的比赛一共做出来两道题,还有一道题做的过程中一直不知道问题出哪了。

D题是比赛结束以后才弄出来的。在比赛的时候,不知道为什么sort函数在ZOJ上面一直越界,貌似是我的排序函数写的有问题,现在只是知道错在比较函数,但是还是不知道为什么错。后来把比较函数改过来以后,就一直WA。找不到问题。然后看了别人的题解,发现我把问题理解错了。问题中给出的是每个LV的百分比,而不是在前多少名到哪个LV。改正以后才正确。说起来也好玩,在比赛的时候sort函数一直不对,然后一着急就写了个冒泡排序。。

代码如下:

#include<iostream>
#include<algorithm>
using namespace std;
struct member{
	int ID;
	string date;
	int score;
};

bool operator < (const member& a,const member& b){
	if(a.score!=b.score)return a.score>b.score;
	if(a.date!=b.date)return a.date<b.date;
	return a.ID<b.ID;
}

member aa[2050];
int ori[2050];

int main(){
//	freopen("data.txt","r",stdin);
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	int tot=0;
	while(T--){
		int n;
		cin>>n;
		int tot=n;
		for(int i=0;i<n;++i){
			cin>>aa[i].ID;
			cin>>aa[i].date;
			cin>>aa[i].score;
			ori[i]=aa[i].ID;
			if(aa[i].score==0){tot--;ori[i]=-1;}
		}
		sort(aa,aa+n);
	//	for(int i=0;i<n;++i){
	//		for(int t=0;t<=n-1-i-1;++t){
	//			if(aa[t]<aa[t+1])continue;
	//			member tmp=aa[t];
	//			aa[t]=aa[t+1];
	//			aa[t+1]=tmp;
	//		}
	//	}
		int lv6=tot*0.03;
		int lv5=tot*0.07+lv6;
		int lv4=tot*0.2+lv5;
		int lv3=tot*0.3+lv4;
		for(int i=0;i<n;++i){
			int pos=0;
			if(ori[i]==-1){cout<<"LV1"<<endl;continue;}
			for(;pos<n;){
				if(ori[i]==aa[pos].ID)break;
				pos++;
			}
	//		cout<<i<<' '<<pos<<endl;
	//		if(aa[pos].score==0){cout<<"LV1"<<endl;continue;}
			pos++;
			if(pos<=lv6){cout<<"LV6"<<endl;continue;}
			if(pos<=lv5){cout<<"LV5"<<endl;continue;}
			if(pos<=lv4){cout<<"LV4"<<endl;continue;}
			if(pos<=lv3){cout<<"LV3"<<endl;continue;}
			cout<<"LV2"<<endl;
		}
	}
	return 0;
}


比较函数用下面的几种写法就会崩溃,现在也不知道为什么。有人能指教吗。。

第一种:

bool operator < (const member& a,const member& b){
	bool t=1;
	bool f=0;
	if(a.score>b.score)return a.score>b.score;
	if(a.date<b.date)return a.date<b.date ;
	return a.ID<b.ID;
}
第二种:

bool operator < (const member& a,const member& b){
	if(a.score>b.score)return 1;
	if(a.date<b.date)return 1;
	if(a.ID<b.ID)return 1;
	return 0;
}


第I题的题目看着可难懂了,不过其实看懂了以后就发现其实可简单了。对结果造成影响的只有两个符号,一个是"_",另一个是“?”然后根据他的要求进行操作就可以了。

需要注意的是在输入的里面有空格,所以用string类型再用cin会错的。拷贝以后的字符串会超过原来字符串的长度,不进行特殊处理会越界。

代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

char source[269];
char res[260];
char Hello[]={"Hello, world!"};


int main(){
	ios::sync_with_stdio(false);
//	freopen("data.txt","r",stdin);
	int T;
	cin>>T;
	fflush(stdin);
	cin.get();
	while(T--){
		for(int i=0;i<257;++i){
			res[i]='\0';
			source[i]='\0';
		}
		cin.getline(source,256,'\n');
		fflush(stdin);
	//	cout<<source<<endl;
		int now=0;
		int can=1;
		for(int i=0;i<strlen(source);++i)
		{
			if(!can)break;
			if(source[i]=='_'){
				for(int t=0;t<strlen(source);++t){
					res[now++]=source[t];
					if(now>=257){cout<<"No"<<endl;can=0;break;}
				}
			}
			else if(source[i]=='!'){
				for(int t=0;t<13;++t){
					res[now++]=Hello[t];
					if(now>=257){cout<<"No"<<endl;can=0;break;}
				}
			}
		}
	//	cout<<res<<endl;
		if(!can)continue;
		if(strcmp(res,source)==0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		fflush(stdin);
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值