CODEFORCES228A is your horseshoe on the other hoof? (water problem)

Source: Internet
Author: User
Tags time limit
A. Is your horseshoe on the other hoof?
Click to open the topic
Time limit per test 2 seconds memory limit per test megabytes input standard input output standard output

Valera The Horse is going to the party with friends. He had been following the fashion trends for a while, and he knows that it was very popular to wear all horseshoes of Diffe Rent color. Valera had got four horseshoes left from the last year, but maybe some of them had 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 Comrad Es.

Fortunately, the store sells horseshoes of all colors under the sun and Valera have 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 we need to help Valera and de Termine What's 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. Sample Test (s) Input

1 7 3 3
Output
1
Input
7 7 7 7
Output
3

..... ..................
#include <iostream>
#include <stdlib.h>
using namespace std;
int check (int a[])
{
    int i,k=0;
    for (i=0; i<3; i++)
    {
        if (a[i]!=a[i+1])
            k++;
    }
    return 4-k-1;
}
int cmp (const void *a,const void *b)
{
    return * (int *) a-* (int *) b;
}
int main ()
{
    int a[4],i;
    while (Cin>>a[0])
    {for
        (i=1; i<4; i++)
        {
            cin>>a[i];
        }
        Qsort (A,4,sizeof (a[0]), CMP);
        Cout<<check (a) <<endl;
    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.