본문 바로가기

string

(26)
[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] 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] 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] 10988번 팰린드롬인지 확인하기 (C++) https://www.acmicpc.net/problem/10988 10988번: 팰린드롬인지 확인하기 첫째 줄에 단어가 주어진다. 단어의 길이는 1보다 크거나 같고, 100보다 작거나 같으며, 알파벳 소문자로만 이루어져 있다. www.acmicpc.net #include #include #include using namespace std; int main() { string s1, s2; cin >> s1; s2 = s1; reverse(s1.begin(), s1.end()); if(s1 == s2) cout
[BOJ] 1316번 그룹 단어 체커 (C++) https://www.acmicpc.net/problem/1316 1316번: 그룹 단어 체커 그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때 www.acmicpc.net #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, cnt = 0; cin >> n; string str; for(int i = 0; i > str; set s; char last = ' '..