Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. FILE *fin = fopen("input.txt", "r");
  5. FILE *fout = fopen("output.txt", "w");
  6.  
  7. int N, a[100];
  8. fscanf(fin, "%d", &N);
  9. for (int i = 0; i < N; i++) {
  10. fscanf(fin, "%d", &a[i]);
  11. }
  12. for (int i=0; i < N-2; i++) {
  13. while (((a[i] >= a[i + 1]) && (a[i + 2] <= a[i+1])) || ((a[i] <= a[i + 1]) && (a[i + 2] <= a[i+1]))) {
  14. if ((a[i] >= a[i + 1]) && (a[i + 2] <= a[i+1])) {
  15. a[i+2]++;
  16. }
  17. if ((a[i] <= a[i + 1]) && (a[i + 2] >= a[i+1])) {
  18. a[i]++;
  19. }
  20. }
  21. }
  22. for (int i=0; i<N; i++) {
  23. fprintf(fout, "%d ", a[i]);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement