CodeForces-228A-Is your horseshoe on the other hoof?(set方便好理解)

该博客介绍了一个编程竞赛题目,要求帮助Valera在参加聚会时确保他的四个马蹄铁颜色各不相同。输入为四个整数,代表Valera已有的马蹄铁颜色。通过创建一个集合来存储不重复的颜色,然后计算需要购买的不同颜色马蹄铁的数量。提供的C++代码实现了这一解决方案,通过找出已有的不同颜色数量并用4减去这个数量得出需要购买的马蹄铁数。
摘要由CSDN通过智能技术生成

A. Is your horseshoe on the other hoof?

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output

Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.

Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.

Input
The first line contains four space-separated integers s1, s2, s3, s4 (1 ≤ s1, s2, s3, s4 ≤ 109) — the colors of horseshoes Valera has.

Consider all possible colors indexed with integers.

Output
Print a single integer — the minimum number of horseshoes Valera needs to buy.

Examples
input
1 7 3 3
output
1
input
7 7 7 7
output
3
链接:https://codeforces.ml/problemset/problem/228/A
题意:给你4个数字,需要四个数字要均不相同
思路:根据set中没有重复的元素 可以用4-s.size()来解决
ac代码如下:

#include<iostream>
#include<set>
using namespace std;
int main(){
	set<int> s;
	int a=4;
	int c;
	while(a--){
		cin>>c;
		if(s.find(c)==s.end()){
			s.insert(c);
		}
	}
	cout<<4-s.size()<<endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值