Advertisement
liwgfr

Untitled

Sep 30th, 2021
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package space.enthropy.lesson1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class BinoclaR {
  6.     public static void main(String[] args) {
  7.         Scanner in = new Scanner(System.in);
  8.         int n = in.nextInt();
  9.         char[] ar = new char[n];
  10.         int cntYo = 0;
  11.         int cntYe = 0;
  12.  
  13.         for (int i = 0; i < n; i++) {
  14.             ar[i] = in.next().charAt(0);
  15.             if (ar[i] == 'е') {
  16.                 cntYe++;
  17.             } else if (ar[i] == 'ё') {
  18.                 cntYo++;
  19.                 ar[i] = 'е';
  20.             }
  21.         }
  22.         for (int i = 1; i < n; i++) {
  23.             for (int j = 0; j < n; j++) {
  24.                 if (ar[i] < ar[j]) {
  25.                     char temp = ar[j];
  26.                     ar[j] = ar[i];
  27.                     ar[i] = temp;
  28.                 }
  29.             }
  30.         }
  31.         for (int i = 0; i < n; i++) {
  32.             if (cntYe == 0 && cntYo != 0 && ar[i] == 'е') {
  33.                 ar[i] = 'ё';
  34.                 cntYo--;
  35.             } else if (cntYe != 0 && ar[i] == 'е') {
  36.                 cntYe--;
  37.             }
  38.             System.out.print(ar[i] + " ");
  39.         }
  40.         System.out.println();
  41.         for (int i = n - 1; i >= 0; i--) {
  42.             if (cntYe == 0 && cntYo != 0) {
  43.                 ar[i] = 'ё';
  44.                 cntYo--;
  45.             }
  46.             if (cntYe != 0) {
  47.                 cntYe--;
  48.             }
  49.             System.out.print(ar[i] + " ");
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement