Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashSet;
- import java.util.Scanner;
- public class _1_CognateWords {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- String inputLine = scan.nextLine().trim();
- String[] words = inputLine.split("[^A-Za-z]+");
- HashSet<String> cognateWords = new HashSet<>();
- int w1, w2;
- String foundWords;
- for (w1 = 0; w1 < words.length; w1++) {
- for (w2 = 0; w2 < words.length; w2++) {
- if (w2 != w1) {
- for (String rightStr : words) {
- boolean isFoundCognateWords = words[w1].concat(
- words[w2]).equals(rightStr);
- if (isFoundCognateWords) {
- foundWords = String.format("%s|%s=%s", words[w1],
- words[w2], rightStr);
- cognateWords.add(foundWords);
- }
- }
- }
- }
- }
- if (cognateWords.isEmpty()) {
- System.out.println("No");
- } else {
- for (String lineStr : cognateWords) {
- System.out.println(lineStr);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement