10 Aug 2021
스택을 활용한 문제
#include <iostream>
#include <string>
#include <stack>
using namespace std;
bool check(char c1, char c2){
if ((c1=='(' && c2==')') || (c1=='[' && c2==']')) return true;
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
string str = "";
while(1) {
getline(cin, str);
if (str.length()==1 && str[0]=='.') break;
stack<char> s;
bool flag = true;
for (int i=0; i<str.length(); i++) {
if(str[i]=='(' || str[i]=='[') s.push(str[i]);
if(str[i]==')' || str[i]==']') {
if (!s.empty()){
if(check(s.top(), str[i])) s.pop();
else {
flag = false;
break;
}
}
else {
flag = false;
break;
}
}
}
if (flag==false) cout << "no" << endl;
else {
if(s.empty()) {
cout << "yes" << endl;
continue;
}
else cout << "no" << endl;
}
}
return 0;
}
오늘 너무 창피하고 창피하다 반성해야지 ㅜㅜ… 앞으로는 더더 열심히 할테니 제발 좋은 일들만 있게 해주세요…제발제발…🙏🏼🙏🏼🙏🏼
09 Aug 2021
DFS로 풀리는 문제… 아직도 헷갈려 어질어질
#include <iostream>
#include <vector>
using namespace std;
vector<int> virus[101];
bool check[101];
int dfs_count(int x) {
int count=0;
check[x] = true;
for (int i=0; i<virus[x].size(); i++) {
int y = virus[x][i];
if (!check[y]) {
dfs_count(y);
count++;
}
}
return count;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n, m;
cin >> n >> m;
for (int i=0; i<m; i++) {
int u, v;
cin >> u >> v;
virus[u].push_back(v);
virus[v].push_back(u);
}
int ans = dfs_count(1);
cout << ans << endl;
}
너무 기대를 많이 하고 김칫국도 많이 마셨더니 현실을 부정하게된다… 에이 설마~ 아닐거야 에이~ 아닐거야….. 나한테만은…이라는 이기적인 생각 ㅜㅜ 머리가 아프다… 눈물도 날 것 같다ㅜㅜ 화도 난다… 얼른 자자!
05 Aug 2021
기본 수학 연산 카테고리에 제일 정답률이 높았던 문제!@@!@!
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int x[4], y[4];
for (int i = 0; i < 3; i++) cin >> x[i] >> y[i];
x[3] = x[0];
y[3] = y[0];
if (x[3] == x[1]) x[3] = x[2];
else if (x[3] == x[2]) x[3] = 1;
if (y[3] == y[1]) y[3] = y[2];
else if (y[3] == y[2]) y[3] = y[1];
cout << x[3] << " " << y[3] << endl;
return 0;
}
