Advertisement
video_game

fezriddle.java

May 5th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.49 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Collections;
  4. import java.util.LinkedList;
  5. import java.util.Scanner;
  6.  
  7. public class run {
  8.  
  9.     /**
  10.      * @param args
  11.      * @throws FileNotFoundException
  12.      */
  13.     public static void main(String[] args) throws FileNotFoundException {
  14.         File wordlist = new File("words.txt");
  15.         Scanner s = new Scanner(wordlist);
  16.         LinkedList<String> lst = new LinkedList<String>();
  17.         tryNextWord: do {
  18.             String str = s.nextLine();
  19.             if (str.length() == 8) {
  20.                 String ucstr = str.toUpperCase();
  21.                 int AGSM = 2, BHNT = 3, EJKQX = 1, IOCUV = 1, FLRY = 1;
  22.                 for (int i = 0; i < 8; i++) {
  23.                     switch (ucstr.toUpperCase().charAt(i)) {
  24.                         case 'A':
  25.                         case 'G':
  26.                         case 'S':
  27.                         case 'M':
  28.                             AGSM--;
  29.                             break;
  30.                         case 'B':
  31.                         case 'H':
  32.                         case 'N':
  33.                         case 'T':
  34.                             BHNT--;
  35.                             break;
  36.                         case 'I':
  37.                         case 'O':
  38.                         case 'C':
  39.                         case 'U':
  40.                         case 'V':
  41.                             IOCUV--;
  42.                             break;
  43.                         case 'F':
  44.                         case 'L':
  45.                         case 'R':
  46.                         case 'Y':
  47.                             FLRY--;
  48.                             break;
  49.                         case 'Q':
  50.                         case 'J':
  51.                         case 'X':
  52.                         case 'E':
  53.                         case 'K':
  54.                             EJKQX--;
  55.                             break;
  56.                         default:
  57.                             continue tryNextWord;
  58.                     }
  59.                     if (AGSM < 0 || BHNT < 0 || EJKQX < 0 || IOCUV < 0 || FLRY < 0) {
  60.                         continue tryNextWord;
  61.                     }
  62.                 }
  63.                 lst.add(Character.toUpperCase(str.charAt(0))+str.substring(1));
  64.             }
  65.         } while (s.hasNextLine());
  66.         Collections.sort(lst);
  67.         for(String str : lst)
  68.             System.out.println(str);
  69.         System.out.println("---------\n"+lst.size());
  70.         s.close();
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement