Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by minhtienbukai501 ( 5 years ago )
#include <iostream>
using namespace std;

void SortMang(int* a, int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (a[i] < a[j])
			{
				int temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
}

void TimPhanTuPhanBiet(int a[], int n, int PhanTuPhanBiet[], int &m)
{
	m = 0;

	for (int i = 0; i < n; i++)
	{
		bool check = true;
		for (int j = i - 1; j >= 0; j--)
		{
			if (a[i] == a[j])
			{
				check = false;
				break;
			}
		}

		if (check == true)
		{
			PhanTuPhanBiet[m++] = a[i];
		}
	}

	SortMang(PhanTuPhanBiet, m);
	
}


int main()
{
	int n;
	int a[100];
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	int m;
	int PhanBiet[100];

	TimPhanTuPhanBiet(a, n, PhanBiet, m);
	int ThuHang[100];
	int thuhang = 1;
	int dem = 0;
	for (int i = 0; i < m; i++)
	{
		thuhang += dem;
		dem = 0;
		for (int j = 0; j < n; j++)
		{
			if (PhanBiet[i] == a[j])
			{
				ThuHang[j] = thuhang;
				dem++;
			}		
		}
	}
	
	for (int i = 0; i < n; i++)
	{
		cout << ThuHang[i] << endl;
	}

	return 0;
}

 

Revise this Paste

Your Name: Code Language: