Loading...

[백준] 5648번 역원소 정렬 (C++, 정렬)

예제를 보고 알아서 정렬 조건을 만들어줘야 된다. 0을 없애기 위해 문자열을 정수로 변환한 후 다시 문자열로 만들어줬다 #define _CRT_SECURE_NO_WARNINGS #define rep(i,s,e) for(int i=s;i> n; rep(i, 0, n) { cin >> tmp; reverse(tmp.begin(), tmp.end()); a.push_back(to_string(stol(tmp))); } sort(a.begin(),a.end(),cmp); for (auto x : a) { cout

[백준] 11652번 카드 (C++, 정렬)

일단 저장해놓고 정렬한 후 최대 갯수 갱신하며 답 찾아나가는 방법 #define _CRT_SECURE_NO_WARNINGS #define rep(i,s,e) for(int i=s;i> n; long long num[100001]; rep(i, 0, n) { cin >> num[i]; } sort(num, num + n); int cnt = 1; int max = 1; long long ans = num[0]; rep(i, 1, n) { if (num[i] == num[i - 1]) { cnt += 1; if (max < cnt) { max = cnt; ans = num[i]; } } else { cnt = 1; } } cout

[백준] 1431번 시리얼 번호 (C++, 정렬)

C++ 어려버 ㅠㅠ 새 언어로 처음부터 다시 하려니 힘들다 #define _CRT_SECURE_NO_WARNINGS #define rep(i,s,e) for(int i=s;i='0' && a[i]= '0' && b[i] > n; vector v(n); rep(i, 0, n) { cin >> v[i]; } sort(v.begin(), v.end(), cmp); for (auto x : v) { cout

[백준] 17219번 비밀번호 찾기 (C++, 해시)

#define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; unordered_map hash; string add, pass; for (int i = 0; i > add >> pass; hash[add] = pass; } string tmp; for (int i = 0; i > tmp; cout

[백준] 13414번 수강신청 (C++, 해시)

큐에다가 순서대로 집어넣는데 만약 같은 사람이 한번 더 신청하면 인덱스번호를 변경해서 큐에다 한번 더 넣는다. 나중에 큐에서 뺄때 해시에 저장된 인덱스번호와 다르면 그냥 넘어가고 같으면 해당 순서가 맞으므로 출력한다. #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); int k, l; unordered_map hash; cin >> k >> l; string num; queue q; for (int i = 0; i > num;..

[백준] 1620번 나는야 포켓몬 마스터 이다솜 (C++, 해시)

번호도 문자열 형태로 저장해버림 #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include using namespace std; bool comp(string a,string b) { return a>b; } int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); int n,m; cin >> n>>m; unordered_map poketmon; string name; for (int i = 0; i > name; poketmon.insert({ name,to_string(i + 1) }); poketmon.insert({ to_string(i..

[SWEA] 2948. 문자열 교집합 (C++, 해시)

해시에 첫 집합의 문자열들을 저장하고 두 번째 문자열 집합을 입력받을 때 검색해서 해시에 들어있는 문자열의 개수를 세준다. #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); int t, n, m; cin >> t; for (int tc = 1; tc > n >> m; string s; unordered_map hash; int cnt = 0; for (int i = 0; i > s; hash.insert({ s,s }); } for (int ..

[SWEA] 1256. K번째 접미어 (C++)

뒤에서부터 한 문자씩 끊어서 vector에 저장한 다음 사전순 정렬했다 #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include using namespace std; int t,k; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); cin >> t; string s; for (int tc = 1; tc > k; cin >> s; vector list; string tmp = ""; for (int i = s.length()-1; i>=0; i--) { tmp = s[i]+tmp; list.push_back(tmp); } sort(list.begin(), list.end()); cout

[백준] 1012번 유기농 배추 (C++, BFS)

1인곳을 만나서 visit상태가 아니면 bfs를 돌린다. bfs돌리게 되는 횟수 = 지렁이 개수 #define _CRT_SECURE_NO_DEPRECATE #include #include #include using namespace std; #define MAX 51 int n,t,m,k; int map[MAX][MAX]; bool vis[MAX][MAX]; int ypos[] = { 0,0,1,-1 }; int xpos[] = { 1,-1,0,0 }; int cnt = 0; void bfs(int i,int j) { queue q; q.push({ i,j }); vis[i][j] = true; while (q.size() > 0) { int y, x; tie(y, x) = q.front(); q.pop..

[swexpert] 1230. 암호문3 (C++, 연결리스트)

연결리스트를 구현을 하면 좋으련만 c++을 다시 공부하면서 stl도 아직 모르는게 많아서 문제 많이 풀면서 익숙해지는게 먼저인 것 같다. #define _CRT_SECURE_NO_DEPRECATE #include #include #include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); for (int tc = 1; tc > n; // 암호문 길이 for (int i = 0; i > x; l.push_back(x); } cin >> n; //명령어 개수 while (n--) { cin >> tmp; if (tmp == 'I') { cin >> x >> y; auto ite..