Varianta 25 bacalaureat informatica 2007

Cerinte si rezolvari


{pdf=pdf/bacalaureat2007/varianta_025.pdf|600|600}

Rezolvari
1)
#include<fstream.h>
ifstream f("bac.txt");
#include<math.h>
int i,n;
float min;
struct vect {
float x,y;
};
vect v[100];
void citire()
{
f>>n;
for(i=1;i<=n;i++)

f>>v[i].x>>v[i].y;

}
void f1()
{
min=sqrt(pow(v[1].x,2)+pow(v[1].y,2));

for(i=2;i<=n;i++)
if(sqrt(pow(v[i].x,2)+pow(v[i].y,2)) < min)
{
min=sqrt(pow(v[i].x,2)+pow(v[i].y,2));

}
}
void f2()
{

for(i=1;i<=n;i++)
{
float d = sqrt(pow(v[i].x,2)+pow(v[i].y,2));
if(d == min)

cout<<"("<<v[i].x<<","<<v[i].y<<")"<<" ";
}
}
void main()
{
citire();
f1();
f2();
}
2)
#include<iostream.h>
int f(int n)
{
if(n==1)
return 1;
else
if(n%2==0)
return 2*f(n/2)+3;
else
if(n%2==1)
return 2*f(n/2);
}
void main()
{
int ok=0;
long x;
cin>>x;
for(long i=1;i<=10000000;i++)
if(f(i)==x)
{
ok=1;
x=10000001;
}
if(ok)
cout<<"DA";
else cout<<"NU";

}
3)
#include<iostream.h>
#include<math.h>
void cifra(long nr,int &max,int &ap)
{
int l=log10(nr)+1;


while(nr)
{
if(nr%10>max)
{
max=nr%10;
ap=1;
}
else
if(nr%10==max)
ap++;
nr/=10;
}

}

void main()
{
long a;
int max=0,ap=0;
cin>>a;
cifra(a,max,ap);
if(max==9 && ap>1)
cout<<"DA";
else
cout<<"NU";

}