Bear and Five Cards

Problem:Bear and Five Cards

Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won’t discard cards if it’s impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?

Input:
The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.

Output:
Print the minimum possible sum of numbers written on remaining cards.

Sample Input 1:
7 3 7 3 20

Sample Output 1:
26

Sample Input 2:
7 9 3 1 8

Sample Output 2:
28

Sample Input 3:
10 10 10 10 10

Sample Output 3:
20

Note:
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.

Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.

You are asked to minimize the sum so the answer is 26.
In the second sample, it’s impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It’s optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.

Language:C

#include <stdio.h>

int min(int a,int b)
{
  int min;
  if(a<b) min=a;
  else  min=b;
  return min;
}

int main()
{
  int card[101]={0};
  int number;
  int sum=0;
  for(int i=1;i<=5;i++)
  {
    scanf("%d",&number);
    sum+=number;
    card[number]++;
  }

  int temp;
  int copysum=sum;
  for(number=1;number<=100;number++)
  {
    temp=copysum;
    if(card[number]>1&&card[number]<4)
    {
      temp-=card[number]*number;
      sum=min(sum,temp);
    }

    if(card[number]>=4)
    {
      temp-=number*3;
      sum=min(sum,temp);
      break;
    }

  }

  printf("%d\n",sum);

  return 0;
}
Bear 编译数据库是一个用于帮助开发者生成和维护代码编辑器的编译数据库的工具。编译数据库是一组描述代码文件的元数据,包括每个文件的编译指令、编译选项、头文件和源代码之间的依赖关系等。 Bear 编译数据库的目的是为了帮助开发者通过为编辑器提供准确的编译数据库来改善代码的智能功能,如自动补全、代码导航、语法检查和重构等。通过使用编译数据库,编辑器能够更好地理解代码,并提供更准确和有用的代码建议。 使用 Bear 编译数据库的步骤大致如下: 1. 首先,需要安装 Bear 编译数据库工具。可以通过在终端中运行相应的命令,使用包管理器(如apt、yum、brew等)安装该工具。 2. 安装完成后,运行 bear make 命令,该命令会在当前工作目录中执行 make 命令,并生成编译数据库。可以根据具体需求,使用不同的编译器选项来生成数据库,如 -C (--clean) 参数可以清除现有数据库,重新生成新的。 3. 生成的编译数据库文件默认为 compile_commands.json,它是一个 JSON 格式的文件,描述了项目中所有源代码文件的编译相关信息。 4. 将生成的编译数据库文件移动到编辑器所需的位置。不同的编辑器可能需要将数据库文件放置在不同的目录中,具体可以参考编辑器的文档。 通过以上步骤,开发者就可以使用 Bear 编译数据库来改善代码编辑体验。需要注意的是,由于生成的编译数据库中包含了源代码文件的路径信息,因此在将数据库文件与他人共享或在不同的机器上使用时,需要注意路径的一致性,以避免编辑器无法正确解析编译数据库的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值