Cod sursa(job #539684)

Utilizator dragosd2000Dumitrache Dragos dragosd2000 Data 23 februarie 2011 11:24:36
Problema Cautare binara Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include<fstream.h>
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
long n,m,i,a[100000],b[100000][2];
void cit()
{
	fin>>n;
	for(i=1;i<=n;i++)
		fin>>a[i];//citim vectorul
	fin>>m;
	for(i=1;i<=m;i++)
		fin>>b[i][1]>>b[i][2];
}
void cautare()
{
	int j,k;
	for(i=1;i<=m;i++)
	{	
		if(b[i][1]==0)
		{
			for(j=1;j<=n;j++)
				if(a[j]==b[i][2])
					k=j;
			fout<<k<<'\n';
		}
		if(b[i][1]==1)
		{
			for(j=1;j<=n;j++)
				if(a[j]<=b[i][2])
					k=j;
			fout<<k<<'\n';
		}			
		if(b[i][1]==2)
		{
			for(j=n;j>=1;j--)
				if(a[j]>=b[i][2])
					k=j;
			fout<<k<<'\n';
		}
	}
}
int main()
{
	cit();
	cautare();
	
	return 0;
}