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 files via upload #2

Open
wants to merge 1 commit into
base: 9월-10일---스택,-큐,-덱
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
63 changes: 63 additions & 0 deletions 1935_HW.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Created by kirin on 2021-09-16.
//

// 후위 표기식 2

#include <iostream>
#include <stack>
#include <map>

using namespace std;

int main(){
int n;
double a,b; // 연산을 위한 변수
string input;
map<char, int> alphabet; //n개의 피연산자에 대한 정보 담음
//vector<char> calc; //연산자들 담은 벡터
stack<double> s; //연산을 위한 스택

//calc.assign(4,{'+','-','*','/'});

//입력
cin>>n;
cin>>input;
char last_alphabet = 'A'+n; // 각 피연산자에 값 할당 위해서 마지막 알파벳 파악하기

for(char a='A'; a<last_alphabet; a++){
cin>>alphabet[a];
}

//연산
for(int i=0; i<input.size(); i++){
if(input[i] == '+' || input[i] == '-' || input[i] == '*' || input[i] == '/'){//연산자이면 그에 상응하는 연산 수행
b= s.top();
s.pop();
a= s.top();
s.pop();

switch(input[i]){
case '+':
s.push(a+b);
break;
case '-':
s.push(a-b);
break;
case '*':
s.push(a*b);
break;
case '/':
s.push(a/b);
break;
}
}
else{ //알파벳이면 push
s.push(alphabet[input[i]]);

}
}
cout<<fixed;
cout.precision(2); //출력되는 double 자리수 고정시키기 위해!
cout<<s.top();
}
41 changes: 41 additions & 0 deletions 20920_HW.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Created by kirin on 2021-09-16.
//

//영어단어장 만들기

#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main(){
int n,m; // 단어 개수 & 암기 해야하는 단어 길이 기준
map<string, int> words_number; // 단어와 나온 개수
vector<string> words;
vector<bool> flag; // 해당 단어가 나왔는지 안나왔는지 알기 위해
// (map도 vector assign처럼 초기화 가능한가..? 초기화 하는 법 모르겠어서 vector 사용)

//입력
cin>>n>>m;
for(int i=0; i<n; i++){
cin>>words[i];
}

//초기화
flag.assign(n,false);
words.assign(n,{});

//연산
for(int i=0; i<n; i++){
if(!flag[i]){ //false이면 한 번도 안나온 단어니까 새롭게 추가
words_number[words[i]] = 1;
flag[i] = true;
}
else{ // 이미 나온 단어는 개수만 추가
words_number[words[i]] ++;
}
}

}