Compare commits
10
Commits
1b04b8248e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c0f837ec4 | ||
|
|
ee04348241 | ||
|
|
45bc3315cb | ||
|
|
cc2bf52800 | ||
|
|
7de3a54b4f | ||
|
|
837c83dbe6 | ||
|
|
c4fa7ed822 | ||
|
|
a1f8bd13e6 | ||
|
|
f6b9eb2a18 | ||
|
|
457eb4a71f |
-10
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="module" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="src" path=""/>
|
|
||||||
<classpathentry kind="output" path=""/>
|
|
||||||
</classpath>
|
|
||||||
+2
-13
@@ -1,15 +1,4 @@
|
|||||||
/Week2.class
|
|
||||||
/Week4.class
|
|
||||||
/Week4Bonus.class
|
|
||||||
/Task.class
|
|
||||||
/Week9$1.class
|
|
||||||
/Week9$2.class
|
|
||||||
/Week9$3.class
|
|
||||||
/Week9.class
|
|
||||||
/Week9Gui.class
|
|
||||||
/Task$CompareByTitle.class
|
|
||||||
/Week9$4.class
|
|
||||||
/Task$SortByTitleComparator.class
|
|
||||||
.vscode
|
.vscode
|
||||||
.classpath
|
.classpath
|
||||||
.project
|
.project
|
||||||
|
*.class
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>club-challenges</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
</natures>
|
|
||||||
<filteredResources>
|
|
||||||
<filter>
|
|
||||||
<id>1698871122678</id>
|
|
||||||
<name></name>
|
|
||||||
<type>30</type>
|
|
||||||
<matcher>
|
|
||||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
|
||||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
|
||||||
</matcher>
|
|
||||||
</filter>
|
|
||||||
</filteredResources>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
import java.io.File;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This challenge is inspired from LeetCode Problem 193.
|
||||||
|
*
|
||||||
|
* Given an input file called "inut.txt" that contains a list of potential
|
||||||
|
* phone numbers on each line, determine if each line is a valid phone number.
|
||||||
|
*
|
||||||
|
* A valid phone number is defined as any sequence of digits that has the
|
||||||
|
* following characteristics:
|
||||||
|
* 1. It may contain a '+' at the start of the string, for the international
|
||||||
|
* dialing code. The '+' is optional.
|
||||||
|
*
|
||||||
|
* 2. It may contain a '-' in the string, to separate the country code, area
|
||||||
|
* code, and local number. The '-' is optional.
|
||||||
|
*
|
||||||
|
* 3. It may contain a '(' and ')' in the string, to enclose the area code.
|
||||||
|
*/
|
||||||
|
public class ParsePhone {
|
||||||
|
private static boolean isValidNumber(String number) {
|
||||||
|
char[] chars = number.toCharArray();
|
||||||
|
|
||||||
|
Queue q = new Queue();
|
||||||
|
for(int i = 0; i < chars.length; i++) {
|
||||||
|
if(Character.isDigit(chars[i]))
|
||||||
|
q.enqueue(Integer.parseInt(chars[i] + ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(q.getSize() != 10) return false;
|
||||||
|
else return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Queue {
|
||||||
|
private Node head;
|
||||||
|
private Node tail;
|
||||||
|
private int size;
|
||||||
|
|
||||||
|
public Queue() {
|
||||||
|
head = null;
|
||||||
|
tail = head;
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enqueue(int value) {
|
||||||
|
Node newNode = new Node(value);
|
||||||
|
if(head == null) {
|
||||||
|
head = newNode;
|
||||||
|
tail = head;
|
||||||
|
size++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tail.setNext(newNode);
|
||||||
|
tail = newNode;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node dequeue() {
|
||||||
|
if(head == null) return null;
|
||||||
|
|
||||||
|
Node tmp = head;
|
||||||
|
head = head.next;
|
||||||
|
|
||||||
|
size--;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Node {
|
||||||
|
private Node next;
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
public Node(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext() {
|
||||||
|
return next != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node getNext() {
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNext(Node next) {
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
File input = new File("input.txt");
|
||||||
|
|
||||||
|
if(input.exists() == false) {
|
||||||
|
System.out.println("File not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Scanner sc = new Scanner(input);
|
||||||
|
|
||||||
|
while(sc.hasNextLine()) {
|
||||||
|
String number = sc.nextLine();
|
||||||
|
System.out.println(isValidNumber(number) ? number : "Invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.close();
|
||||||
|
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
987-123-4567
|
||||||
|
123 456 7890
|
||||||
|
(123) 456-7890
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
javac *.java
|
||||||
|
java ParsePhone
|
||||||
|
rm *.class
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
53..7....
|
||||||
|
6..195...
|
||||||
|
.98....6.
|
||||||
|
8...6...3
|
||||||
|
4..8.3..1
|
||||||
|
7...2...6
|
||||||
|
.6....28.
|
||||||
|
...419..5
|
||||||
|
....8..79
|
||||||
Reference in New Issue
Block a user