1.笨笨熊搬家打包篇
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int comp(int a,int b)
{
return a>b;
}
int main()
{
int v,n,m=0,input,first,last;
vector<int> A;
cin >> v;
cin >> n;
for(int i=0;i!=n;i++)
{
cin >> input;
A.push_back(input);
}
sort(A.begin(),A.end(),comp);
first=0;
last=A.size()-1;
if(n==1)
m=1;
while(first<last)
{
if(A[first]+A[last]<v+1)
{
m++;
first++;
last--;
}
else
{
m++;
first++;
}
if(first==last)
m++;
}
cout<<m<<endl;
return 0;
}
2.打牌
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int i,len,lenb,flag;
char card[1001],b[1001];
int count[10];
while(scanf("%s %s",card,b) != EOF)
{
flag = 0;
memset(count, 0, sizeof(count));
len = strlen(card);
lenb = strlen(b);
for(i = 0;i < len;i++){
count[card[i]-'0']++;
}
if(lenb < 5)
{
for(i = b[0] - '0' + 1;i < 10;i++)
{
if(count[i] >= strlen(b)){
flag = 1;
break;
}
}
}
else if(lenb == 5){
for(i = b[0] - '0' + 1;i < 6;i++)
{
if(count[i] > 0 && count[i+1] > 0 && count[i+2] > 0 && count[i+3] > 0 && count[i+4] > 0){
flag = 1;
break;
}
}
}
if(flag == 0){
printf("NO\n");
}
else{
printf("YES\n");
}
}
return 0;
}
3.扑克牌排序
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i,j,k=0,sum=0,n=-1,a[13]={2,1,13,12,11,10,9,8,7,6,5,4,3},c[54];
string b;
cin>>b;
for(i=0;i<b.size();i++)
{
if(b[i]!=',')
sum=sum*10+b[i]-'0';
if(b[i]==','||i==b.size()-1){
c[k++]=sum;
sum=0;
}
}
for(i=0;i<13;i++)
{
for(j=0;j<k;j++)
{
if(a[i]==c[j])
{ n++;
if(n!=k-1) cout<<c[j]<<",";
else cout<<c[j];
}
}
}
return 0;
}