-
-
Notifications
You must be signed in to change notification settings - Fork 587
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
Showing
13 changed files
with
231 additions
and
13 deletions.
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,19 @@ | ||
with Text_IO; use Text_IO; | ||
|
||
procedure Fizz_Buzz is | ||
Counter : Integer := 1; | ||
begin | ||
while Counter < 101 | ||
loop | ||
if Counter mod 3 = 0 and Counter mod 5 = 0 then | ||
Put_Line("FizzBuzz"); | ||
elsif Counter mod 3 = 0 then | ||
Put_Line("Fizz"); | ||
elsif Counter mod 5 = 0 then | ||
Put_Line("Buzz"); | ||
else | ||
Put_Line(Integer'Image(Counter)); | ||
end if; | ||
Counter := Counter + 1; | ||
end loop; | ||
end Fizz_Buzz; |
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,34 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <cctype> // for std::isspace | ||
|
||
|
||
int main(int argc, char* argv[]) { | ||
|
||
// Check if given string passed | ||
if (argc < 2) { | ||
std::cout << "Usage: please provide a string" << std::endl; | ||
return 1; // Return error code if no string is given | ||
} | ||
|
||
// Get the string passed | ||
std::string input = argv[1]; | ||
std::string result; | ||
|
||
// Check if input string is empty | ||
if (input.empty()) { | ||
std::cout << "Usage: please provide a string" << std::endl; | ||
return 1; // Exit error code if the string is empty | ||
} | ||
|
||
for(char c : input) { | ||
// If the character is not a whitespace character, add it to result | ||
if (!std::isspace(static_cast<unsigned char>(c))) { | ||
result += c; | ||
} | ||
} | ||
//print out the result (string should have no spaces) | ||
std::cout << result << std::endl; | ||
|
||
return 0; | ||
} |
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,71 @@ | ||
using System; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace SamplePrograms | ||
{ | ||
public class LongestPalindromicSubstring | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
string input = string.Join(" ", args); | ||
Console.WriteLine(LongestPalindrome(input)); | ||
} | ||
|
||
public static string LongestPalindrome(string input) | ||
{ | ||
if (string.IsNullOrEmpty(input) || !ContainsPalindrome(input)) | ||
{ | ||
return "Usage: please provide a string that contains at least one palindrome"; | ||
} | ||
|
||
int start = 0; | ||
int end = 0; | ||
|
||
for (int i = 0; i < input.Length; i++) | ||
{ | ||
int lengthOne = ExpandAroundCenter(input, i, i); | ||
int lengthTwo = ExpandAroundCenter(input, i, i + 1); | ||
int length = Math.Max(lengthOne, lengthTwo); | ||
|
||
if (length > end - start) | ||
{ | ||
start = i - (length - 1) / 2; | ||
end = i + length / 2; | ||
} | ||
} | ||
return input.Substring(start, end - start + 1); | ||
} | ||
|
||
private static int ExpandAroundCenter(string input, int left, int right) | ||
{ | ||
while (left >= 0 && right < input.Length && input[left] == input[right]) | ||
{ | ||
left--; | ||
right++; | ||
} | ||
return right - left - 1; | ||
} | ||
|
||
private static bool ContainsPalindrome(string input) | ||
{ | ||
string[] words = input.Split(' '); | ||
foreach (string word in words) | ||
{ | ||
if (word.Length > 1 && word == Reverse(word)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
string cleanedInput = input.Replace(" ", ""); | ||
return cleanedInput.Length > 1 && cleanedInput == Reverse(cleanedInput); | ||
} | ||
|
||
private static string Reverse(string input) | ||
{ | ||
char[] charArray = input.ToCharArray(); | ||
Array.Reverse(charArray); | ||
return new string(charArray); | ||
} | ||
} | ||
} |
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,27 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
public class LongestWord | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
// check for empty string or empty input | ||
if (args.Length == 0 || args[0] == "") { | ||
Console.WriteLine("Usage: please provide a string"); | ||
} else { | ||
// stores string from args | ||
string sentence = args[0]; | ||
|
||
// split string by whitespace (these four special characters), removes empty entries | ||
string[] words = sentence.Split(new[] {' ', '\t', '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
// sort array by length in descending order so longest string is first and returns is to array | ||
words = words.OrderByDescending(word => word.Length).ToArray(); | ||
|
||
// log the length of longest word | ||
Console.WriteLine(words[0].Length); | ||
} | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.