Problema #1320 pbinfo imi zice cineva ce e gresit va rog?
#include
#include
using namespace std;
int v[1002],n,i=1,descrescator=true,crescator=true,cresc=false,descresc=false,k=1,lafel=true,descresc2=false,cresc2=false;
int main() {
cin>>n;
for(i=1;i<=n;i++)
cin>>v[i];
for(i=1;i
if(v[i]>v[i+1])
crescator=false;
}
for(i=1;i
if(v[i]
descrescator=false;
}
for(i=1;i
if(v[i]
k++;
if(k==n)
cresc=true;
}
k=1;
for(i=1;i
if(v[i]>v[i+1])
k++;
if(k==n)
descresc=true;
}
for(i=1;i
if(v[i]!=v[i+1])
lafel=false;
}
k=1;
for(i=1;i
if(v[i]>=v[i+1])
k++;
if(k==n)
descresc2=true;
}
k=1;
for(i=1;i
if(v[i]<=v[i+1])
k++;
if(k==n)
cresc2=true;
}
if(crescator==false && descrescator==false)
cout<<"sir neordonat";
if(lafel==true)
cout<<"sir constant";
if(cresc==true)
cout<<"sir strict crescator";
if(descresc==true )
cout<<"sir strict descrescator";
if(descresc2==true && descresc==false)
cout<<"sir descrescator";
if(cresc2==true && cresc==false
)
cout<<"sir crescator";
return 0;
}
Răspunsuri la întrebare
#include <iostream>
using namespace std;
int main(){
int n, i, v[1001];
bool cresc = true, descresc = true, strict = true;
cin >> n >> v[1];
for (i = 2;i <= n;i++){
cin >> v[i];
if (v[i] > v[i-1])
descresc = false;
else if (v[i] < v[i-1])
cresc = false;
else strict = false;
}
if (cresc && descresc && !strict)
cout << "sir constant";
else if (cresc && !descresc && strict)
cout << "sir strict crescator";
else if (cresc && !descresc && !strict)
cout << "sir crescator";
else if (!cresc && descresc && strict)
cout << "sir strict descrescator";
else if (!cresc && descresc && !strict)
cout << "sir descrescator";
else cout << "sir neordonat";
return 0;
}