Untitled

Anonymous
plain_text
10/17/2026 4:17 PM
1.1 KB
4
Indexable
#include<iostream>
#include<string>
using namespace std;



int main() 
{
	
	short t;
	cin >> t;

	while (t--)
	{
		short n;
		cin >> n;
		int arr[105];
		for (short i = 0; i < n; i++)
		{
			cin >> arr[i];
		}
		int count = 0, counter = 0, counter2 = 0;;
		for (short z = 0; z < n; z++)
		{
			bool already_counted = false;
			for (short x = 0; x < z; x++)
			{
				if (arr[z] == arr[x]) {
					already_counted = true;
					break;
				}
			}
			if (already_counted) continue;
			count = arr[z];
			for (short x = 0; x < n; x++)
			{
				if (arr[z] == arr[x])
				{
					counter++;
				}
			}
			if (counter < count)
			{
				counter2+=counter;
			}
			else if(counter>count)
			{
				counter2 += counter - count;
			}
			counter = 0;
		}
		cout << counter2 << endl;
	}
	return 0;
}
Editor is loading...
Leave a Comment