Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.3 kB
5
Indexable
Never
package com.company;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ds = new String[1000];
        int []dem= new int[100];
        int n = 0;
        while (sc.hasNext()) {
            String temp = sc.next();
            if (thuanNghich(temp)) {
                int t = tim(temp, ds, n);
                if (t == -1) {
                    ds[n] = temp;
                    dem[n] = 1;
                    n++;
                } else
                    dem[t]++;
            }
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            if (ds[i].length() > max)
                max = ds[i].length();
        }
        for (int i = 0; i < n; i++) {
            if (ds[i].length() == max) {
                int t = tim(ds[i],ds,n);
                System.out.println(ds[i] + " " + dem[t]);
            }
        }
    }

    public static boolean thuanNghich(String s) {
        StringBuilder re = new StringBuilder(s);
        re.reverse();
        return s.equals(re.toString());
    }

    public static int tim(String s, String[] ds, int n) {
        for (int i = 0; i < n; i++) {
            if (ds[i].equals(s)) return i;
        }
        return -1;
    }
}