B. Canvas Frames

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.

Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length.

Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).

Output

Print the single number — the maximum number of frames Nicholas can make for his future canvases.

Sample test(s)
input
5
2 4 3 2 3
output
1
input
13
2 2 4 4 4 4 6 6 6 7 7 9 9
output
3
input
4
3 3 3 5
output
0

解题说明:此题就是判断有多少对相同的数字,这里由于范围较小,可以用数组来保存次数


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
	int n,i,temp;
	int count;
	int flag;
	int a[101];
	for(i=0;i<101;i++)
	{
		a[i]=0;
	}
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&temp);
		a[temp]++;
	}
	flag=0;
	count=0;
	for(i=0;i<101;i++)
	{
		if(a[i]>=2)
		{
			a[i]-=2;
			if(flag<2)
			{
				flag++;
			}
			if(flag==2)
			{
				count++;
				flag=0;
			}
			if(a[i]>=2)
			{
				i--;
			}
		}
	}
	printf("%d\n",count);
	return 0;
}


你可能感兴趣的:(B. Canvas Frames)