Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Collections;
- import java.util.LinkedList;
- import java.util.Scanner;
- public class run {
- /**
- * @param args
- * @throws FileNotFoundException
- */
- public static void main(String[] args) throws FileNotFoundException {
- File wordlist = new File("words.txt");
- Scanner s = new Scanner(wordlist);
- LinkedList<String> lst = new LinkedList<String>();
- tryNextWord: do {
- String str = s.nextLine();
- if (str.length() == 8) {
- String ucstr = str.toUpperCase();
- int AGSM = 2, BHNT = 3, EJKQX = 1, IOCUV = 1, FLRY = 1;
- for (int i = 0; i < 8; i++) {
- switch (ucstr.toUpperCase().charAt(i)) {
- case 'A':
- case 'G':
- case 'S':
- case 'M':
- AGSM--;
- break;
- case 'B':
- case 'H':
- case 'N':
- case 'T':
- BHNT--;
- break;
- case 'I':
- case 'O':
- case 'C':
- case 'U':
- case 'V':
- IOCUV--;
- break;
- case 'F':
- case 'L':
- case 'R':
- case 'Y':
- FLRY--;
- break;
- case 'Q':
- case 'J':
- case 'X':
- case 'E':
- case 'K':
- EJKQX--;
- break;
- default:
- continue tryNextWord;
- }
- if (AGSM < 0 || BHNT < 0 || EJKQX < 0 || IOCUV < 0 || FLRY < 0) {
- continue tryNextWord;
- }
- }
- lst.add(Character.toUpperCase(str.charAt(0))+str.substring(1));
- }
- } while (s.hasNextLine());
- Collections.sort(lst);
- for(String str : lst)
- System.out.println(str);
- System.out.println("---------\n"+lst.size());
- s.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement