본문 바로가기

Algorithm

(203)
[BOJ] 1263번 시간 관리 (C++) https://www.acmicpc.net/problem/1263 1263번: 시간 관리 진영이는 캠프 조교를 온 후 효율적으로 시간 관리를 해야 한다는 것을 깨달았다. 진영이는 하루에 해야 할 일이 총 N개가 있고 이 일들을 편하게 1번부터 N번까지 차례대로 번호를 붙였다. 진영 www.acmicpc.net #include #include #include using namespace std; bool compare(pair& a, pair& b) { return a.second > b.second; } int main() { int n, t, s, tmp = 0, left = 0; cin >> n; vector v(n); for (int i = 0; i > t >> s; ..
[BOJ] 14490번 백대열 (C++) https://www.acmicpc.net/problem/14490 14490번: 백대열 n과 m이 :을 사이에 두고 주어진다. (1 ≤ n, m ≤ 100,000,000) www.acmicpc.net #include #include using namespace std; int gcd(int a, int b){ if(b == 0) return a; else return gcd(b, a % b); } int main() { string s; cin >> s; int idx = s.find(":"); int n = stoi(s.substr(0, idx)); int m = stoi(s.substr(idx + 1, -1)); int gcf = gcd(n, m); cout
[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..