22-真题
作者:
把头发掀起来看世界
,
2024-11-22 20:39:58
,
所有人可见
,
阅读 1
1.无人机打耙
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=40;
int b,r,g,p;
struct robot
{
string color;
int score;
bool operator< (const robot &t)const {
return score>t.score;
}
}ro[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
char c;
cin>>c>>ro[i].score;
if(c=='b') {b++;ro[i].color="blue";}
else if(c=='r') {r++;ro[i].color="red";}
else if(c=='g') {g++;ro[i].color="green";}
else {p++;ro[i].color="purple";}
}
cout<<"blue"<<" "<<b<<endl;
cout<<"green"<<" "<<g<<endl;
cout<<"purple"<<" "<<p<<endl;
cout<<"red"<<" "<<r<<endl;
sort(ro,ro+n);
for(int i=0;i<n;i++)
cout<<ro[i].score<<" "<<ro[i].color<<endl;
return 0;
}
2.顺子
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <vector>
using namespace std;
bool isStraight2(vector<int>& num)
{
int ma=-1,mi=15,w=0,n=0;
unordered_set<int> s;
for(int x:num)
{
if(x==0) {w++;continue;}
ma=max(ma,x);
mi=min(mi,x);
if(s.count(x)) return false;
else
{
s.insert(x);
n++;
}
}
int d=ma-mi+1;
if(n==5 && d==5)return true;
else if(n==4 && (d==5 ||d==4))return true;
else if(n==3 && (d>=3||d<=5))return true;
else return false;
}
int main()
{
vector<int> num(5);
for(int i=0;i<5;i++)
{
char x;
cin>>x;
if(x=='A')num[i]=1;
else if(x=='J')num[i]=11;
else if(x=='Q')num[i]=12;
else if(x=='K')num[i]=13;
else if(x=='W'||x=='w')num[i]=0;
else num[i]=x-'0';
}
if(isStraight2(num))cout<<"顺子"<<endl;
else cout<<"不是顺子"<<endl;
return 0;
}