Răspuns :
Răspuns:
Iti trimit o solutie de 100p verificata. Numerele prime se verifica intr-o functie. Succes!
#include <iostream>
using namespace std;
int x, j, n;
bool ok;
bool nrprim(int nr)
{
int i;
bool prim = true;
for(i = 2; i * i <= nr; i ++)
if(nr % i == 0)
{
prim = false;
break;
}
return prim;
}
int main()
{
cin >> n;
for(j = 1; j <= n; j ++)
{
cin >> x;
if(nrprim(x)) ok = true;
}
if(ok) cout << "DA";
else cout << "NU";
return 0;
}
Explicație:
Răspuns:
#include <iostream>
using namespace std;
int main()
{
int N, a,b, st_cr=1, st_descr=1, i, gasit=0, gasit2=0;
cin >> N;
cin >> a >> b;
i=2;
while (a<b && i<N-1) {
++st_cr; gasit=1;
a=b; cin >> b;
++i;
}
if (i==N && a>b) {
++st_descr;
gasit2=1;
}
else {
a=b; cin >> b; ++i;
if (a>b && i<=N) {++st_descr; gasit2=1;}
while (a>b && i<N) {
++st_descr; gasit2=1;
a=b; cin >> b;
++i;
}
}
if (gasit && gasit2 && st_cr+st_descr==N) cout << 1;
else cout << 0;
return 0;
}
Explicație:
Cu vector este cu mult mai simplă logica... aici e nu prea...
Sper să te descurci cu acest cod... De sunt întrebări, sunt aici..
Succese!