From 06b44c5d08fae20b42713b3341a322da5985982d Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sat, 13 Aug 2022 14:32:13 +0800 Subject: [PATCH] style: add clang-format configuration --- .clang-format | 137 ++++++++++++++++++ .../README.md | 2 +- .../README_EN.md | 2 +- .../Solution.cpp | 4 +- .../2370.Longest Ideal Subsequence/README.md | 6 +- .../README_EN.md | 6 +- .../Solution.cpp | 6 +- 7 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000000..293451ddcfb19 --- /dev/null +++ b/.clang-format @@ -0,0 +1,137 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: false +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +... + diff --git a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README.md b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README.md index 010e389edba08..4d39cd2eb85a9 100644 --- a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README.md +++ b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README.md @@ -198,7 +198,7 @@ public: bool dfs(int i) { if (i == n) return true; - if (f[i] != -1 ) return f[i] == 1; + if (f[i] != -1) return f[i] == 1; bool res = false; if (i < n - 1 && nums[i] == nums[i + 1]) res = res || dfs(i + 2); if (i < n - 2 && nums[i] == nums[i + 1] && nums[i + 1] == nums[i + 2]) res = res || dfs(i + 3); diff --git a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README_EN.md b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README_EN.md index 72d825befd862..cfa4b5bb348e8 100644 --- a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README_EN.md +++ b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/README_EN.md @@ -163,7 +163,7 @@ public: bool dfs(int i) { if (i == n) return true; - if (f[i] != -1 ) return f[i] == 1; + if (f[i] != -1) return f[i] == 1; bool res = false; if (i < n - 1 && nums[i] == nums[i + 1]) res = res || dfs(i + 2); if (i < n - 2 && nums[i] == nums[i + 1] && nums[i + 1] == nums[i + 2]) res = res || dfs(i + 3); diff --git a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/Solution.cpp b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/Solution.cpp index 6835621968e0c..85f2716fa5796 100644 --- a/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/Solution.cpp +++ b/solution/2300-2399/2369.Check if There is a Valid Partition For The Array/Solution.cpp @@ -3,7 +3,7 @@ class Solution { vector f; vector nums; int n; - + bool validPartition(vector& nums) { n = nums.size(); this->nums = nums; @@ -13,7 +13,7 @@ class Solution { bool dfs(int i) { if (i == n) return true; - if (f[i] != -1 ) return f[i] == 1; + if (f[i] != -1) return f[i] == 1; bool res = false; if (i < n - 1 && nums[i] == nums[i + 1]) res = res || dfs(i + 2); if (i < n - 2 && nums[i] == nums[i + 1] && nums[i + 1] == nums[i + 2]) res = res || dfs(i + 3); diff --git a/solution/2300-2399/2370.Longest Ideal Subsequence/README.md b/solution/2300-2399/2370.Longest Ideal Subsequence/README.md index e6f4b63d092d4..b53b1f05a5ac8 100644 --- a/solution/2300-2399/2370.Longest Ideal Subsequence/README.md +++ b/solution/2300-2399/2370.Longest Ideal Subsequence/README.md @@ -127,11 +127,9 @@ public: vector dp(n, 1); unordered_map d; d[s[0]] = 0; - for (int i = 1; i < n; ++i) - { + for (int i = 1; i < n; ++i) { char a = s[i]; - for (char b = 'a'; b <= 'z'; ++b) - { + for (char b = 'a'; b <= 'z'; ++b) { if (abs(a - b) > k) continue; if (d.count(b)) dp[i] = max(dp[i], dp[d[b]] + 1); } diff --git a/solution/2300-2399/2370.Longest Ideal Subsequence/README_EN.md b/solution/2300-2399/2370.Longest Ideal Subsequence/README_EN.md index b651ee16c32e9..fce6dfafb437a 100644 --- a/solution/2300-2399/2370.Longest Ideal Subsequence/README_EN.md +++ b/solution/2300-2399/2370.Longest Ideal Subsequence/README_EN.md @@ -107,11 +107,9 @@ public: vector dp(n, 1); unordered_map d; d[s[0]] = 0; - for (int i = 1; i < n; ++i) - { + for (int i = 1; i < n; ++i) { char a = s[i]; - for (char b = 'a'; b <= 'z'; ++b) - { + for (char b = 'a'; b <= 'z'; ++b) { if (abs(a - b) > k) continue; if (d.count(b)) dp[i] = max(dp[i], dp[d[b]] + 1); } diff --git a/solution/2300-2399/2370.Longest Ideal Subsequence/Solution.cpp b/solution/2300-2399/2370.Longest Ideal Subsequence/Solution.cpp index 6a9a007b1134a..ec53ec2794295 100644 --- a/solution/2300-2399/2370.Longest Ideal Subsequence/Solution.cpp +++ b/solution/2300-2399/2370.Longest Ideal Subsequence/Solution.cpp @@ -6,11 +6,9 @@ class Solution { vector dp(n, 1); unordered_map d; d[s[0]] = 0; - for (int i = 1; i < n; ++i) - { + for (int i = 1; i < n; ++i) { char a = s[i]; - for (char b = 'a'; b <= 'z'; ++b) - { + for (char b = 'a'; b <= 'z'; ++b) { if (abs(a - b) > k) continue; if (d.count(b)) dp[i] = max(dp[i], dp[d[b]] + 1); }