본문 바로가기

algorithm

(198)
[BOJ] 1302번 베스트셀러 (C++) https://www.acmicpc.net/problem/1302 1302번: 베스트셀러 첫째 줄에 오늘 하루 동안 팔린 책의 개수 N이 주어진다. 이 값은 1,000보다 작거나 같은 자연수이다. 둘째부터 N개의 줄에 책의 제목이 입력으로 들어온다. 책의 제목의 길이는 50보다 작거나 같고 www.acmicpc.net #include #include using namespace std; int main() { int n, max = 0; string str, result; map m; cin >> n; for(int i = 0; i > str; if(m.find(str) != m.end()){ m[str]++; } else{ m[str] = 1; } } for(auto it ..
[BOJ] 7656번 만능 오라클 (C++) https://www.acmicpc.net/problem/7656 7656번: 만능 오라클 입력은 한 줄로 된 1000자 이내의 단락이 주어진다. 포함된 문자는 대소문자, 띄어쓰기, 하이픈(hyphen), 어퍼스트로피(apostrophe), 반점(comma), 세미콜론(semicolon), 온점(period)과 물음표(question mark)이다. www.acmicpc.net #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); string str; getline(cin, str); int start, end = -1; while(str.find("What", end + 1) != -1..
[BOJ] 4358번 생태학 (C++) https://www.acmicpc.net/problem/4358 4358번: 생태학 프로그램은 여러 줄로 이루어져 있으며, 한 줄에 하나의 나무 종 이름이 주어진다. 어떤 종 이름도 30글자를 넘지 않으며, 입력에는 최대 10,000개의 종이 주어지고 최대 1,000,000그루의 나무가 주어 www.acmicpc.net #include #include #include using namespace std; int main() { string str; map m; float cnt = 0; while(getline(cin, str)){ cnt++; if(m.find(str) == m.end()){ m[str] = 1; } else{ m[str]++; } } cout second / cnt) * 100; c..
[BOJ] 19583번 싸이버개강총회 (C++) https://www.acmicpc.net/problem/19583 19583번: 싸이버개강총회 첫번째 줄에는 개강총회를 시작한 시간 S, 개강총회를 끝낸 시간 E, 개강총회 스트리밍을 끝낸 시간 Q가 주어진다. (00:00 ≤ S > t1 >> t2 >> t3; set first; int s =..
[BOJ] 2941번 크로아티아 알파벳 (C++) https://www.acmicpc.net/problem/2941 2941번: 크로아티아 알파벳 예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z= www.acmicpc.net #include #include using namespace std; int main() { string cro[8] = { "c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z=" }; string str; cin >> str; for(int i = 0; i < 8; i++){ while(1){ int idx = str.find(..
[BOJ] 23028번 5학년은 다니기 싫어요 (C++) https://www.acmicpc.net/problem/23028 23028번: 5학년은 다니기 싫어요 2022년 1학기에는 전공 수업이 4과목, 비전공 수업이 3과목이 주어진다. 아리는 전공 2과목, 비전공 2과목을 듣게 되면 전공학점이 66학점, 총 학점이 132학점이 된다. 그래서 총 8학기 안에 졸업을 www.acmicpc.net #include using namespace std; int main() { int n, a, b, x, y; cin >> n >> a >> b; int rs = 8 - n; // 남은 학기 int rg = 66 - a; // 남은 전공 학점 int rc = 130 - b; // 남은 총 학점 for(int i = 0; i > x >> y..
[BOJ] 20291번 파일 정리 (C++) https://www.acmicpc.net/problem/20291 20291번: 파일 정리 친구로부터 노트북을 중고로 산 스브러스는 노트북을 켜자마자 경악할 수밖에 없었다. 바탕화면에 온갖 파일들이 정리도 안 된 채 가득했기 때문이다. 그리고 화면의 구석에서 친구의 메시지를 www.acmicpc.net #include #include #include using namespace std; int main() { int n; cin >> n; string str; map m; for(int i = 0; i > str; int idx = str.find('.'); str = str.substr(idx + 1); if(m.find(str) != m.end()){ m[str]++; ..
[BOJ] 18870번 좌표 압축 (C++) https://www.acmicpc.net/problem/18870 18870번: 좌표 압축 수직선 위에 N개의 좌표 X1, X2, ..., XN이 있다. 이 좌표에 좌표 압축을 적용하려고 한다. Xi를 좌표 압축한 결과 X'i의 값은 Xi > Xj를 만족하는 서로 다른 좌표의 개수와 같아야 한다. X1, X2, ..., XN에 좌 www.acmicpc.net #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector v(n); for (int i = 0; i > v[i]; } vector tmp(v); ..