Skip to content
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

Add Algo_11, 13 #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions KJE/BJ1085.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
using namespace std;
int main(){
int x,y,w,h;
cin>>x>>y>>w>>h;
int tmp;

if(x>y){
tmp=y;
}
else{
tmp=x;
}

if(w-x>h-y){
if(h-y>tmp){
cout<<tmp;
}
else{
cout<<h-y;
}

}

else{

if(w-x>tmp){
cout<tmp;
}
else{
cout<<w-x;
}

}

return 0;
}
Empty file added KJE/BJ1181.cpp
Empty file.
26 changes: 26 additions & 0 deletions KJE/BJ13116.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
using namespace std;
//공통된 부모노드를 찾아라

int main(){
int T,a,b;
cin>>T;
for(int i=0;i<T;i++){
cin>>a>>b;
}
while(a!=b){
if(a>b){
a=a/2;
}
else if(a<b){
b=b/2;
}
else{
a=a/2;
b=b/2;
}
cout<<a*10<<endl; //b*10 해도 된다

}

}
19 changes: 19 additions & 0 deletions KJE/BJ9372.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <string.h>
using namespace std;

//예제를 보니까 국가마다 다 이어져 있음
int main(){
int T,N,M,a,b;
cin>>T;
while(T--){
cin>>N>>M; //국가의 수, 비행기의 종류
for(int i=0;i<M;i++){
cin>>a>>b;
}
cout<<N-1<<endl;
}
//너무 단순한데 이게 맞나요..

return 0;
}
37 changes: 37 additions & 0 deletions KJE/Tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//트리 구조 구현
//전위순회: root->left->right
#include <iostream>
using namespace std;

typedef struct Node{
int data;
struct Node*left;
struct Node*right;
}Node;

//루트 왼쪽 오른쪽 순
struct Node n1={1, NULL,NULL};
struct Node n2={4, &n1, NULL};
struct Node n3={16, NULL, NULL};
struct Node n4={25, NULL, NULL};
struct Node n5={20, &n3, &n4};
struct Node n6={15, &n2, &n5};
struct Node *current=&n6; //current가 루트
//계속 오류가 났던 이유,,
//Struct Node에서 int data를 맨 마지막에 썼는데 맨 위에 썼어야 했다. 순서 주의

void Preorder(Node*current){
if(current){
cout<<current->data<<endl;
Preorder(current->left);
Preorder(current->right);
}
}

int main(){

cout<<"전위순회"<<endl;
Preorder(current);
return 0;
//출력: 15-4-1-20-16-25
}