- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Iterator;
- import java.util.Scanner;
- import java.util.Vector;
- public class Main {
- //static Vector<String> list ;
- //static Sets set;
- //private static Scanner scan;
- //private static Scanner scanstr;
- public static void
- main(String[] args)
- throws IOException{
- Scanner scanstr;
- Sets set
- =
- null;
- Vector
- list =
- new
- Vector
- ();
- System.out.println(
- "choose the way to initualize keyboard(1) or file(2),1 or 2:"
- );
- Scanner scans
- =
- new Scanner(System.in);
- int
- i =
- scans.nextInt();
- if
- (i == 1
- ){
- System.out.println(
- "type \" \" to quit"
- );
- while(scans.hasNextLine()){
- String str
- =
- scans.nextLine();
- if
- (str.equals(" "
- )){
- break;
- }
- if
- (list.contains(str))
- continue;
- else list.add(str);
- }
- set
- =
- new MyString(list);
- }
- if
- (i == 2
- ){
- list
- =
- FileInput();
- set
- =
- new MyString(list);
- }
- System.out.println(
- "choose how to operate Strings"
- );
- System.out.println(
- "getOrder(1),findString(2),findSet(3)"
- );
- System.out.println(
- "interset(4),times(5),add(6),delete(7),print(8)"
- );
- while(scans.hasNextInt()){
- scanstr
- =
- new Scanner(System.in);
- i
- =
- scans.nextInt();
- switch(i){
- case
- 1
- :
- set.getOrder();
- set.myTostring();
- break;
- case
- 2
- :
- boolean bool1;
- System.out.println(
- "type the string to find"
- );
- String strtemp
- =
- scanstr.nextLine();
- bool1
- =
- set.findString(strtemp);
- if(bool1){
- System.out.println(
- "find"+strtemp+"in strings"
- );
- }
- else{
- System.out.println(
- "404!"
- );
- }
- break;
- case
- 3
- :
- boolean bool2;
- Vector
- list1 =
- new
- Vector
- ();
- System.out.println(
- "type the strings set to find"
- );
- System.out.println(
- "type \" \" to quit"
- );
- while(scanstr.hasNextLine()){
- String str2
- =
- scanstr.nextLine();
- if
- (str2.equals(" "
- )){
- break;
- }
- if
- (list1.contains(str2))
- continue;
- else list1.add(str2);
- }
- bool2
- =
- set.findSet(list1);
- if(bool2){
- System.out.println(
- "find set in strings"
- );
- }
- else{
- System.out.println(
- "404!"
- );
- }
- break;
- case
- 4
- :
- Vector
- list2 =
- new
- Vector
- ();
- System.out.println(
- "type the strings set to find"
- );
- System.out.println(
- "type \" \" to quit"
- );
- while(scanstr.hasNextLine()){
- String str
- =
- scanstr.nextLine();
- if
- (str.equals(" "
- )){
- break;
- }
- if
- (list2.contains(str))
- continue;
- else list2.add(str);
- }
- list2
- =
- set.interset(list2);
- Iterator
- iter =
- list2.iterator();
- while(iter.hasNext()){
- String strs
- =
- iter.next();
- System.out.println(strs);
- }
- break;
- case
- 5
- :
- System.out.println(
- "type the times to caculate"
- );
- String strtemp1
- =
- scanstr.nextLine();
- int
- j = 0
- ;
- j
- =
- set.times(strtemp1);
- System.out.println(strtemp1
- +" "+
- j);
- break;
- case
- 6
- :
- System.out.println(
- "type the string to add"
- );
- String strtemp2
- =
- scanstr.nextLine();
- set.add(strtemp2);
- set.myTostring();
- break;
- case
- 7
- :
- System.out.println(
- "type the string to delete"
- );
- String strtemp3
- =
- scanstr.nextLine();
- set.delete(strtemp3);
- set.myTostring();
- break;
- }
- }
- scans.close();
- }
- public static
- Vector FileInput()
- throws IOException{
- FileReader reader
- =
- new
- FileReader("in.txt"
- );
- int temp;
- Vector
- list;
- list
- =
- new
- Vector
- ();
- StringBuffer b
- =
- new StringBuffer();
- while
- ((temp = reader.read()) != -1
- ){
- if
- ((
- char
- )temp == '\r'
- ){
- String s
- =
- b.toString();
- b.delete(
- 0
- , b.length());
- if(list.contains(s)){
- continue;
- }
- else{
- list.add(s);
- continue;
- }
- }
- else if
- ((
- char
- )temp == '\n'
- ){
- continue;
- }
- else{
- b.append((char)temp);
- }
- }
- reader.close();
- return list;
- }
- }
来源: http://www.bubuko.com/infodetail-2163590.html