알고리즘 문제/Programmers
이상한 문자 만들기
parkit
2019. 5. 5. 02:52
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/12930
기초적인 문제이다.
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 33 34 35 36 37 38 39 40 41 42 43 44 | #include <iostream> #include <deque> #include <list> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> #include <set> #pragma warning(disable:4996) #pragma comment(linker, "/STACK:336777216") using namespace std; string solution(string s) { string answer = ""; int pos = 0; for (int i = 0; i < s.length(); i++) { if (!(pos % 2)) answer += ('a' <= s.at(i) && s.at(i) <= 'z') ? s.at(i) -= 'a' - 'A' : s.at(i); else answer += ('A' <= s.at(i) && s.at(i) <= 'Z') ? s.at(i) += 'a' - 'A' : s.at(i); ++pos; if (s.at(i) == ' ') pos = 0; } return answer; } int main(void) { cout << solution("try hello world") << '\n'; return 0; } | cs |
728x90
반응형