Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class CoupleFrequency {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.         String input = in.nextLine();
  10.         double couples = 0;
  11.         double totalCouples = 0;
  12.        
  13.         String[] numbers = input.split(" ");
  14.         ArrayList<String> used = new ArrayList<> ();
  15.        
  16.         for (int i = 0; i < numbers.length - 1; i++) {
  17.         String couple = numbers[i] + " " + numbers[i + 1];
  18.         if (used.contains(couple)) {
  19.             continue;
  20.         }
  21.         else {
  22.             used.add(couple);
  23.             for (int j = 0; j < numbers.length - 1; j++) {
  24.                 String testCouple = numbers[j] + " " + numbers[j + 1];
  25.                 if (couple.equals(testCouple)) {
  26.                     couples++;
  27.                 }
  28.             }
  29.         }
  30.         totalCouples += couples;
  31.         couples = 0;
  32.         }
  33.        
  34.         used.clear();
  35.        
  36.         for (int i = 0; i < numbers.length - 1; i++) {
  37.             String couple = numbers[i] + " " + numbers[i + 1];
  38.             if (used.contains(couple)) {
  39.                 continue;
  40.             }
  41.             else {
  42.                 used.add(couple);
  43.                 for (int j = 0; j < numbers.length - 1; j++) {
  44.                     String testCouple = numbers[j] + " " + numbers[j + 1];
  45.                     if (couple.equals(testCouple)) {
  46.                         couples++;
  47.                     }
  48.                 }
  49.             }
  50.             System.out.printf("%s -> %.2f%%",couple, (couples / totalCouples) * 100);
  51.             System.out.println();
  52.             couples = 0;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement