알고리즘 문제/BOJ
11365번 !밀비 급일
parkit
2019. 1. 20. 19:38
728x90
반응형
https://www.acmicpc.net/problem/11365
문자열 처리 문제이다.
getline(cin, s);으로 한 줄의 문장을 전체 다 받아주고,
s.compare("END")를 통해 s가 END인지 검사한다.
reverse(s.begin(), s.end());으로 문자열 처음부터 끝까지 순서를 반대로 바꿔주고,
그대로 cout을 통해 출력한다.
참고) compare
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | string a = "This is sample."; string b = "Test"; if (a.compare(b) == 0) { // 두 문자열 a와 b가 서로 같을 때 } else if (a.compare(b) < 0) { // 문자열 a가 문자열 b보다 '사전순'으로 앞에 있을 때 } else if (a.compare(b) > 0) { // 문자열 a가 문자열 b보다 '사전순'으로 뒤에 있을 때 } | cs |
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 31 32 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; int N = 0; int main(void) { string s; while (1) { getline(cin, s); if (s.compare("END") == 0) break; reverse(s.begin(), s.end()); cout << s << '\n'; } return 0; } | cs |
728x90
반응형