mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-05 03:29:46 +08:00
Add cpplint to validate_filenames (#643)
* Add cpplint to validate_filenames * Update and rename Happy_number.cpp to happy_number.cpp * Update validate_new_filenames.yml * pip install cpplint * python3 -m pip install cpplint * python3 -m pip install --useer cpplint * python3 -m pip install --user cpplint * Update validate_new_filenames.yml * sudo python3 -m pip install cpplint * sudo python3 -m pip install cpplint * uses: actions/setup-python@v1 * Run cpplint first * cpp_exts * tuple * cpplint_modified_files
This commit is contained in:
@@ -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:
|
||||
@@ -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 <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Copyright 2019 TheAlgorithms contributors
|
||||
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user