codeforce 493B. Vasya and Wrestling(多重条件比较)

题本不难,只是要多重处理,另外注意数字和超出int范围。认真读题,好好学习英语~

<pre name="code" class="cpp">#include <iostream>
#include<cstdio>
#include<cmath>
#define LL long long 
using namespace std;
const int maxn=2e5+1;
LL n,q1[maxn],q2[maxn],top1,top2,sum1,sum2;
int main(int argc, char *argv[]) {
	//freopen("cin.txt","r",stdin);
	while(cin>>n){	
		int i,t;
		top1=top2=0;
		sum1=sum2=0;
		for(i=0;i<n;i++){
			scanf("%d",&t);
			if(t>0){
				q1[top1++]=t;
				sum1+=t;
			}
			else {
				q2[top2++]=(-t);
				sum2+=(-t);
			}
		}
		if(sum1!=sum2){
			if(sum1>sum2)printf("first\n");
			else printf("second\n");
		}
		else {
			bool judge=0;
			for(i=0;i<min(top1,top2);i++){
				if(q1[i]>q2[i]){
					printf("first\n");
					judge=1;
					break;
				}
				else if(q1[i]<q2[i]){
					printf("second\n");
					judge=1;
					break;
				}
			}
			if(!judge){
				if(top1>top2){
					printf("first\n");
					judge=1;
				}
				else if(top1<top2){
					printf("second\n");
					judge=1;
				}
			}
			if(!judge){
				if(t>0)printf("first\n"); //here t: the last technique
				else printf("second\n");
			}
		}
	}
	return 0;
}


 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值