Cod sursa(job #689097)

Utilizator gigiibirjoBirjovanu Georgiana gigiibirjo Data 24 februarie 2012 09:27:38
Problema Numarare triunghiuri Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<fstream>
#include<algorithm>
using namespace std;
long v[8001];
int main ()
{
	long n,i,nr,d,j,aux;
	ifstream fin("nrtri.in");
	ofstream fout("nrtri.out");
	fin>>n;
	nr=0;
	for(i=1; i<=n; i++)
		fin>>v[i];
	for(i=1; i<=n-1; i++)
		for(j=i+1; j<=n; j++)
			if(v[i]>v[j])
			{
				aux=v[i];
				v[i]=v[j];
				v[j]=aux;
			}
	for(i=1; i<=n; i++)
		for(j=i+1; j<=n; j++)
			for(d=j+1; d<=n; d++)
				if(v[i]+v[j]>=v[d]) nr++;
	fout<<nr;
	fin.close();
	fout.close();
	return 0;
}