Pagini recente » Cod sursa (job #2647305) | Cod sursa (job #1709203) | Cod sursa (job #2957963) | Cod sursa (job #613772) | Cod sursa (job #3174739)
#include <fstream>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int main()
{
int n,v[100001],m,x,c;
bool gasit=false;
f>>n;
for(int i=1; i<=n; i++)
{
f>>v[i];
}
f>>m;
for(int i=1; i<=m;i++)
{
f>>c>>x;
gasit=false;
if(c==0)
{
for(int j=n; j>=1&&gasit==false; j--)
{
if(v[j]==x)
{
g<<j<<'\n';
gasit=true;}
}
if(gasit==false)
g<<-1<<'\n';
}
else if(c==1)
{
for(int j=n;j>=1&&gasit==false;j--)
{
if(v[j]<=x)
{
g<<j<<'\n';
gasit=true;
}
}
}
else{
for(int j=1;j<=n&&gasit==false;j++)
{
if(v[j]>=x)
{
g<<j<<'\n';
gasit=true;
}
}
}
}
return 0;
}