题解 | #纸牌游戏#
纸牌游戏
http://www.nowcoder.com/practice/ebec6fac8a834bf7aed2d5da7c8aa432
- 标准贪心做法
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<long> cards;
long a;
for(int i = 0 ; i< n ; i++){
cin>>a;
cards.push_back(a);
}
sort(cards.begin(),cards.end(),greater<long>());
int ans = 0;
for(int i = 0; i< n; i++){
//牛牛
if(!(i&1)){
ans+= cards[i];
}else{
ans-= cards[i];
}
}
cout<<ans<<endl;
return 0;
}大厂笔试题题解 文章被收录于专栏
主要是公司笔试题得一些总结
查看3道真题和解析
