-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5198c63
commit 5fa931d
Showing
8 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import java.util.Scanner; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class DuplicateWords { | ||
|
||
public static void main(String[] args) { | ||
|
||
String regex = "\\b([A-Za-z]+)\\b(\\s+\\1\\b)+"; | ||
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); | ||
|
||
Scanner in = new Scanner(System.in); | ||
int numSentences = Integer.parseInt(in.nextLine()); | ||
|
||
while (numSentences-- > 0) { | ||
String input = in.nextLine(); | ||
|
||
Matcher m = p.matcher(input); | ||
|
||
// Check for subsequences of input that match the compiled pattern | ||
while (m.find()) { | ||
input = input.replaceAll(m.group(), m.group(1)); | ||
} | ||
|
||
// Prints the modified sentence. | ||
System.out.println(input); | ||
} | ||
|
||
in.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Scanner; | ||
import javax.xml.bind.DatatypeConverter; | ||
|
||
public class MD5 { | ||
|
||
public static void main(String[] args) { | ||
Scanner in = new Scanner(System.in); | ||
try { | ||
MessageDigest md5 = MessageDigest.getInstance("MD5"); | ||
String input = in.nextLine(); | ||
System.out.println(DatatypeConverter.printHexBinary(md5.digest(input.getBytes())).toLowerCase()); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException("Invalid hashing algorithm"); | ||
} | ||
in.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Scanner; | ||
import javax.xml.bind.DatatypeConverter; | ||
|
||
public class SHA256 { | ||
|
||
public static void main(String[] args) { | ||
Scanner in = new Scanner(System.in); | ||
try { | ||
MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); | ||
String input = in.nextLine(); | ||
System.out.println(DatatypeConverter.printHexBinary(sha256.digest(input.getBytes())).toLowerCase()); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException("Invalid hashing algorithm"); | ||
} | ||
in.close(); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters