27. 无人机
#include<bits/stdc++.h>
using namespace std;
typedef struct{
string color;
int score;
}Team;
bool rule(Team a,Team b){
return a.score>b.score;
}
int N;
int cnt[4]={0};
Team teams[30];
int main(){
cin>>N;
for(int i=0;i<N;++i){
char color;
cin>>teams[i].score>>color;
switch(color){
case 'b': cnt[0]++; teams[i].color="blue"; break;
case 'r': cnt[1]++; teams[i].color="red"; break;
case 'g': cnt[2]++; teams[i].color="green"; break;
case 'p': cnt[3]++; teams[i].color="purple"; break;
}
}
sort(teams,teams+N,rule);
cout<<"blue\t"<<cnt[0]<<endl;
cout<<"red\t"<<cnt[1]<<endl;
cout<<"green\t"<<cnt[2]<<endl;
cout<<"purple\t"<<cnt[3]<<endl<<endl;
for(int i=0;i<N;++i){
cout<<teams[i].score<<" "<<teams[i].color<<endl;
}
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4c83da27e5f3883b1fe716e61185007b.jpeg#pic_center)
28. 扑克牌
#include<bits/stdc++.h>
using namespace std;
vector<int> nums;
int daxiaowang=0;
string pai;
int main(){
for(int i=0;i<5;++i){
cin>>pai;
if(pai=="A"){
nums.push_back(1);
}else if(pai=="2"){
nums.push_back(2);
}else if(pai=="3"){
nums.push_back(3);
}else if(pai=="4"){
nums.push_back(4);
}else if(pai=="5"){
nums.push_back(5);
}else if(pai=="6"){
nums.push_back(6);
}else if(pai=="7"){
nums.push_back(7);
}else if(pai=="8"){
nums.push_back(8);
}else if(pai=="9"){
nums.push_back(9);
}else if(pai=="10"){
nums.push_back(10);
}else if(pai=="J"){
nums.push_back(11);
}else if(pai=="Q"){
nums.push_back(12);
}else if(pai=="K"){
nums.push_back(13);
}else if(pai=="W"){
++daxiaowang;
}
}
sort(nums.begin(),nums.end());
int cnt=0;
for(int i=0;i<nums.size()-1;){
if((nums[i]+1)==nums[i+1]){
++cnt;
++i;
}else if(nums[i]==nums[i+1]){
cout<<"no";
return 0;
}else{
if(daxiaowang){
--daxiaowang;
nums.push_back(nums[i]+1);
sort(nums.begin(),nums.end());
}else{
cout<<"no";
return 0;
}
}
}
if(cnt+1==5){
cout<<"yes";
}else if(nums.size()+daxiaowang==5){
cout<<"yes";
}else{
cout<<"no";
}
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/80b9763f4636021153b65067374b35c2.jpeg#pic_center)
29. 计算机视觉算法
#include<bits/stdc++.h>
using namespace std;
int N,C;
int W[100];
int cnt;
void f(int i,int C,vector<int>& subset){
if(i==N&&C!=0){
return;
}
if(C==0){
++cnt;
for(int k=0;k<subset.size();++k){
cout<<subset[k]<<" ";
}
cout<<endl;
return;
}
for(int k=i;k<N;++k){
if(C>=W[k]){
subset.push_back(W[k]);
f(k+1,C-W[k],subset);
subset.pop_back();
}
}
}
int main(){
cin>>N>>C;
for(int i=0;i<N;++i){
cin>>W[i];
}
sort(W,W+N);
vector<int> subset;
f(0,C,subset);
cout<<"cnt:"<<cnt;
if(!cnt){
cout<<"None";
}
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4bf5e7d421abb7790db68f7a18e51145.jpeg#pic_center)