diff --git a/.github/workflows/validate_new_filenames.yml b/.github/workflows/cpplint_modified_files.yml similarity index 60% rename from .github/workflows/validate_new_filenames.yml rename to .github/workflows/cpplint_modified_files.yml index f201829da..d1d850c1d 100644 --- a/.github/workflows/validate_new_filenames.yml +++ b/.github/workflows/cpplint_modified_files.yml @@ -1,21 +1,34 @@ -name: validate_new_filenames +name: cpplint_modified_files on: [push, pull_request] jobs: - validate_new_filenames: + cpplint_modified_files: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 + - uses: actions/setup-python@v1 + - run: python -m pip install cpplint - run: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - run: git diff origin/master --name-only > git_diff.txt - - name: Validate new filenames + - name: cpplint_modified_files shell: python run: | import os + import subprocess import sys - print(sys.version_info) # legacy Python :-( + + print("Python {}.{}.{}".format(*sys.version_info)) # legacy Python :-( with open("git_diff.txt") as in_file: - cpp_files = sorted(line.strip() for line in in_file - if line.strip().lower().endswith(".cpp")) + modified_files = sorted(in_file.read().splitlines()) + print("{} files were modified.".format(len(modified_files))) + + cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split()) + cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)] + print("{} C++ files were modified.".format(len(cpp_files))) + if not cpp_files: + sys.exit(0) + + print("cpplint:") + print(subprocess.check_output(["cpplint"] + cpp_files).decode("utf-8")) upper_files = [file for file in cpp_files if os.path.basename(file) != os.path.basename(file).lower()] if upper_files: diff --git a/Others/Happy_number.cpp b/Others/happy_number.cpp similarity index 53% rename from Others/Happy_number.cpp rename to Others/happy_number.cpp index f1b100810..7d25a1bbd 100644 --- a/Others/Happy_number.cpp +++ b/Others/happy_number.cpp @@ -1,19 +1,18 @@ /* A happy number is a number whose sum of digits is calculated until the sum is a single digit, and this sum turns out to be 1 */ -#include -using namespace std; -int main() -{ +// Copyright 2019 TheAlgorithms contributors + +#include + +int main() { int n, k, s = 0, d; - cout << "Enter a number:"; - cin >> n; + std::cout << "Enter a number:"; + std::cin >> n; s = 0; k = n; - while (k > 9) - { - while (k != 0) - { + while (k > 9) { + while (k != 0) { d = k % 10; s += d; k /= 10; @@ -22,8 +21,8 @@ int main() s = 0; } if (k == 1) - cout << n << " is a happy number" << endl; + std::cout << n << " is a happy number" << std::endl; else - cout << n << " is not a happy number" << endl; + std::cout << n << " is not a happy number" << std::endl; return 0; }