Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int n, max, min, maxi = 0, mini = 0, flag = 1;
- int arr[1000];
- printf("vvedint razmer ");
- scanf("%d", &n);
- printf("zapolnite massive ");
- for(int i = 0; i < n; i += 1) {
- scanf("%d", &arr[i]);
- }
- max = arr[0];
- min = arr[0];
- maxi = 0;
- mini = 0;
- for(int i = 1; i < n; i += 1) {
- if(arr[i] > max) {
- maxi = i;
- max = arr[i];
- }
- if(arr[i] < min) {
- mini = i;
- min = arr[i];
- }
- }
- if(mini < maxi) {
- if(arr[mini] <= arr[mini+1]) {
- for(int i = mini; i < maxi; i += 1) {
- if(arr[i] > arr[i+1]) {
- flag = 0;
- }
- }
- }
- else if(arr[mini] >= arr[mini + 1]) {
- for(int i = mini; i < maxi; i += 1) {
- if(arr[i] < arr[i+1]) {
- flag = 0;
- }
- }
- }
- }
- else {
- if(arr[maxi] <= arr[maxi+1]) {
- for(int i = maxi; i < mini; i += 1) {
- if(arr[i] > arr[i+1]) {
- flag = 0;
- }
- }
- }
- else if(arr[maxi] >= arr[maxi + 1]) {
- for(int i = maxi; i < mini; i += 1) {
- if(arr[i] < arr[i+1]) {
- flag = 0;
- }
- }
- }
- }
- if(flag == 1) {
- printf("YES");
- }
- else {
- printf("NO");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment