Skip to content

Гусев Иван 312 группа #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Google C/C++ Code Style settings
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# Author: Kehan Xue, kehan.xue (at) gmail.com

Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never # To avoid conflict, set this "Never" and each "if statement" should include brace when coding
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterStruct: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 80
CompactNamespaces: false
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false # Make sure the * or & align on the left
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Left
ReflowComments: false
# SeparateDefinitionBlocks: Always # Only support since clang-format 14
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 4
UseTab: Never
1 change: 0 additions & 1 deletion task_01/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ add_executable(${PROJECT_NAME}_tests ${test_source_list})
target_link_libraries(
${PROJECT_NAME}_tests
GTest::gtest_main
Utils
)

include(GoogleTest)
Expand Down
57 changes: 56 additions & 1 deletion task_01/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
int main() { return 0; }
#include <cmath>
#include <iostream>
#include <vector>
#include "solution.h"


int main() {
std::vector<node> nodes;
std::vector<int> ans;

int N=5;
nodes.resize(N);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'N' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int N=5;
int const N=5;

// список ребер
/*nodes[1 2);*/
nodes[0].neighbours.push_back(1);
nodes[0].neighbours.push_back(4);
nodes[1].neighbours.push_back(2);
nodes[3].neighbours.push_back(0);
nodes[3].neighbours.push_back(4);
nodes[4].neighbours.push_back(1);
nodes[4].neighbours.push_back(2);
for(int i =0; i<N;i++){
nodes[i].id = i;
}

for(int i = 0;i<ans.size();i++){
std::cout<<ans[i]<<"\n";
}

bool flag = true;
ans = solution(nodes);

/*std::vector<node> nodes;*/
/*std::vector<int> ans;*/
/**/
/*int n, k, tmp, N;*/
/*std::cin >> N >> tmp; // колич*/
/*nodes.resize(N);*/
/*// список ребер*/
/*while ((tmp--)>0) {*/
/* std::cin >> n >> k;*/
/* nodes[n].neighbours.push_back(k);*/
/*}*/
/*for(int i =0; i<N;i++){*/
/* nodes[i].id = i;*/
/*}*/
/**/
/*ans = solution(nodes);*/

for(int i = ans.size()-1;i>=0;i--){
std::cout<<ans[i]<<" ";
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]

 = ans.size()-1;i>=0;i--){
   ^



return 0;
}
52 changes: 52 additions & 0 deletions task_01/src/solution.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кодстайл немного не тот, и грязноватый код, не только в этом файле

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "solution.h"



std::vector<int> solution(std::vector<node> nodes){
std::deque<int> gray;
std::vector<int> ans;
int N = nodes.size(),tmp=0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]

  int N = nodes.size(),tmp=0;
          ^

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'N' of type 'int' can be declared 'const' [misc-const-correctness]

  int N = nodes.size(),tmp=0;
  ^

for(int i =0; i<N;i++){
nodes[i].id = i;
std::sort(nodes[i].neighbours.begin(), nodes[i].neighbours.end());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

из-за этого у нас будет сложность большая, в самом худшем поличиться nnlog(n)

}

/*gray.push_back(0);*/
node *current;

tmp=0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: Value stored to 'tmp' is never read [clang-analyzer-deadcode.DeadStores]

  tmp=0;
  ^
Additional context

task_01/src/solution.cpp:16: Value stored to 'tmp' is never read

  tmp=0;
  ^

int i = 0;
while(true){
if(i>=N){
break;
}
if(nodes[i].flag==false){
i++;
continue;
}
gray.push_back(i);
current = &nodes[i];

while(gray.size()){
current = &nodes[gray.back()];
if(!current->flag){
gray.pop_back();
continue;
}
if(current->neighbours.size()<=current->last){
ans.push_back(current->id);
current->flag = false;
gray.pop_back();
continue;
}
tmp = current->neighbours[current->last];
gray.push_back(tmp);
current->last++;
}
i++;
}
return ans;

}


17 changes: 17 additions & 0 deletions task_01/src/solution.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#include <algorithm>
#include <vector>
#include <deque>


class node {
public:
std::vector<int> neighbours;
int last = 0;
int id;
bool flag = true; // белая
};


std::vector<int> solution(std::vector<node> nodes);

95 changes: 93 additions & 2 deletions task_01/src/test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,96 @@
#include <gtest/gtest.h>
#include <vector>

#include "solution.h"

TEST(Test, Simple) {
ASSERT_EQ(1, 1); // Stack []
}
std::vector<node> nodes;
std::vector<int> ans;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'N' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int N=3;
int const N=3;

int N=3;
nodes.resize(N);
// список ребер
nodes[1].neighbours.push_back(2);
nodes[0].neighbours.push_back(2);
nodes[0].neighbours.push_back(1);
for(int i =0; i<N;i++){
nodes[i].id = i;
}

bool flag = true;
ans = solution(nodes);
std::vector<int> assertion = {0,1,2};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSERT_EQ лучше использовать

ASSERT_TRUE(assertion.size() == ans.size());
for(int i = 0;i<ans.size();i++){
flag = flag&&(ans[N-i-1]==assertion[i]);
}
ASSERT_TRUE(flag)<<ans[0]<<" УЭЭЭЭЭЭ";

}

TEST(Test, Simple2) {
std::vector<node> nodes;
std::vector<int> ans;

int N=5;
nodes.resize(N);
// список ребер
/*nodes[1 2);*/
nodes[0].neighbours.push_back(1);
nodes[0].neighbours.push_back(4);
nodes[1].neighbours.push_back(2);
nodes[3].neighbours.push_back(0);
nodes[3].neighbours.push_back(4);
nodes[4].neighbours.push_back(1);
nodes[4].neighbours.push_back(2);
for(int i =0; i<N;i++){
nodes[i].id = i;
}

for(int i = 0;i<ans.size();i++){
std::cout<<ans[i]<<"\n";
}

bool flag = true;
ans = solution(nodes);
std::vector<int> assertion = {3, 0, 4, 1, 2};
ASSERT_TRUE(assertion.size() == ans.size());
for(int i = 0;i<ans.size();i++){
flag = flag&&(ans[N-i-1]==assertion[i]);
}
ASSERT_TRUE(flag)<<ans[0]<<" УЭЭЭЭЭЭ";

}


TEST(Test, Simpl3) {
std::vector<node> nodes;
std::vector<int> ans;

int N=6;
nodes.resize(N);
// список ребер
// 0 -> 1
// V Δ
// 3 -> 4
// 5 -> 2
nodes[0].neighbours.push_back(1);
nodes[5].neighbours.push_back(2);
nodes[3].neighbours.push_back(4);
nodes[0].neighbours.push_back(3);
nodes[4].neighbours.push_back(1);
for(int i =0; i<N;i++){
nodes[i].id = i;
}
bool flag = true;
ans = solution(nodes);
std::vector<int> assertion = {5, 2, 0, 3, 4, 1};
ASSERT_TRUE(assertion.size() == ans.size());
for(int i = 0;i<ans.size();i++){
flag = flag&&(ans[N-i-1]==assertion[i]);
}
ASSERT_TRUE(flag)<<ans[2]<<" УЭЭЭЭЭЭ";

}


2 changes: 2 additions & 0 deletions task_02/src/.clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-std=c++23]
Binary file added task_02/src/a.out
Binary file not shown.
61 changes: 60 additions & 1 deletion task_02/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
#include <cmath>
#include <iostream>
#include <vector>
#include "solution.h"

int main() { return 0; }
/*
______________________
/ . \
| ├── main.cpp |
| ├── solution.cpp |
| ├── solution.h |
| ├── stack.cpp |
| ├── stack.hpp |
| └── test.cpp |
| |
\ 1 directory, 6 files /
----------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
*/
int main() {
std::vector<node> nodes;

int n, k = 0, tmp, N;
N = 4;
tmp = 4; // колич
nodes.resize(N);
// список ребер
std::vector<std::pair<int, int>> loh = {{0, 1}, {1, 2}, {2, 3}, {0, 2}};
while (k < tmp) {
nodes[loh[k].first].neighbours.push_back(loh[k].second);
nodes[loh[k].second].neighbours.push_back(loh[k].first);
k++;
}
/*std::vector<node> nodes;*/
/**/
/*int n, k, tmp, N;*/
/*std::cin >> N >> tmp; // колич*/
/*nodes.resize(N);*/
/*// список ребер*/
/*while ((tmp--)>0) {*/
/* std::cin >> n >> k;*/
/* nodes[n].neighbours.push_back(k);*/
/* nodes[k].neighbours.push_back(n);*/
/*}*/

auto ans = solution(nodes);

std::cout << "\n\n" << ans.first.size() << "\n";
for (int i = 0; i < ans.first.size(); i++) {
std::cout << ans.first[i].first << " " << ans.first[i].second << "\n";
}
std::cout << "~~~~~~~~~~~~~~\n";
for (int i = 0; i < ans.second.size(); i++) {
std::cout << ans.second[i] << " ";
}

return 0;
}
Loading
Loading