first commit

This commit is contained in:
Jose Caban
2025-06-07 11:38:03 -04:00
commit e0316ca3ff
79 changed files with 3155 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.10)
#include(${CMAKE_CURRENT_LIST_DIR}/C/CMakeLists.txt)
include(${CMAKE_CURRENT_LIST_DIR}/Cpp/CMakeLists.txt)
if (!WIN32)
include(${CMAKE_CURRENT_LIST_DIR}/Fortran/CMakeLists.txt)
endif()

View File

@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.10)
# Modify only these if one source file!
project(Cppl33tcode_reversewords)
set(CURRENT_PROJECT_CODE_NAME l33tcode_reversewords)
set(FILE_EXT cpp)
# End
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# We want all the warnings and as errors enabled
if (MSVC)
# warning level 4 and all warnings as errors
add_compile_options(/W4 /WX)
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()
add_executable(${CMAKE_PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/${CURRENT_PROJECT_CODE_NAME}.${FILE_EXT})
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
${EXTRA_INCLUDES}
)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
${EXTRA_LIBS}
)

View File

@@ -0,0 +1,64 @@
// https://leetcode.com/problems/reverse-words-in-a-string/
#include <iostream>
#include <cstring>
#include <string>
#include <string_view>
#include <vector>
using namespace std;
static string_view findWord(const string& str, size_t &index)
{
size_t startIndex, endIndex;
// Start of word
while (index < str.size() && isspace(str[index])) index++;
startIndex = index;
// Last letter
while (index < str.size() && !isspace(str[index])) index++;
endIndex = index;
return string_view(str.c_str() + startIndex, endIndex - startIndex);
}
class Solution {
public:
string reverseWords(string s) {
vector<string_view> words;
size_t index = 0;
do
{
string_view sv = findWord(s, index);
if (!sv.empty())
{
words.push_back(sv);
}
} while (index < s.size());
string toRet;
toRet.reserve(s.size());
for (auto iter = words.crbegin(); iter != words.crend(); iter++)
{
toRet += *iter;
toRet += " ";
}
toRet.resize(toRet.size() - 1);
return toRet;
}
};
int main()
{
Solution s;
cout << s.reverseWords("the sky is blue") << endl;
cout << s.reverseWords(" hello world ") << endl;
cout << s.reverseWords("a good example") << endl;
cout << s.reverseWords(" Bob Loves Alice ") << endl;
}

View File

@@ -0,0 +1,13 @@
trait Solution {
fn reverse_words(s: String) -> String;
}
impl Solution {
pub fn reverse_words(s: String) -> String {
}
}
fn main() {
println!("Hello, World!");
}