반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- Baekjoon
- Girls_In_ICT
- 코드캠프
- 자바스크립트
- props
- 15721
- GirlsInICT해커톤
- ts
- typescript
- Bestawards
- 훈훈한자바스크립트
- nodejs
- BOJ
- 이미지스캔
- getDerivedStateFromProps
- props.key
- 에릭슨엘지
- axios
- 객체인지
- Erricson
- js
- map
- javascript
- 백준
- dataFetching
- react
- filter
- Unmounting
- next
- React.js
Archives
- Today
- Total
민희의 코딩일지
[백준] 1159 - 농구 경기 본문
반응형
https://www.acmicpc.net/problem/1159
1159번: 농구 경기
상근이는 농구의 세계에서 점차 영향력을 넓혀가고 있다. 처음에 그는 농구 경기를 좋아하는 사람이었다. 농구에 대한 열정은 그를 막을 수 없었고, 결국 상근이는 농구장을 청소하는 일을 시작
www.acmicpc.net
알고리즘
구현, 문자열
풀이 (1)
key의 맨 앞의 한 글자만 잘라 map 에 넣어준다.
map의 key 중에 그 글자가 있다면 value+1 을 해주고, 없다면 초기값 1로 세팅해준다.
for(int i=0; i<N; i++) {
key = players[i].substr(0, 1);
if (mp.find(key) != mp.end()) {
mp[key]++;
} else {
mp[key] = 1;
}
}
value 가 4 초과라면 성을 출력, 아니라면 PREDAJA를 출력
for(auto it=mp.begin(); it != mp.end(); it++) {
if (it->second > 4) {
cout << it->first;
isSelect=true;
}
}
if(isSelect==false) {
cout << "PREDAJA";
}
전체코드 (1)
#include <bits/stdc++.h>
using namespace std;
int N;
vector<string> players;
string player, key;
map<string, int> mp;
bool isSelect;
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
isSelect = false;
cin >> N;
for (int i=0; i<N; i++) {
cin >> player;
players.push_back(player);
}
for(int i=0; i<N; i++) {
key = players[i].substr(0, 1);
if (mp.find(key) != mp.end()) {
mp[key]++;
} else {
mp[key] = 1;
}
}
for(auto it=mp.begin(); it != mp.end(); it++) {
if (it->second > 4) {
cout << it->first;
isSelect=true;
}
}
if(isSelect==false) {
cout << "PREDAJA";
}
// PREDAJA
return 0;
}
반응형
'자료구조, 알고리즘' 카테고리의 다른 글
[백준] 2559 - 수열 (0) | 2023.09.27 |
---|
Comments