teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2020/04/29 11:40

投稿

episteme
episteme

スコア16612

answer CHANGED
@@ -24,4 +24,27 @@
24
24
  std::cout << '[' << line << "] -> [" << change(line) << "]\n";
25
25
  }
26
26
  }
27
+ ```
28
+
29
+ [追記] <cctype> 使えとの思し召しなら:
30
+ ```C++
31
+ #include <iostream>
32
+ #include <string>
33
+ #include <algorithm>
34
+ #include <cctype>
35
+
36
+ std::string change(const std::string& str) {
37
+ std::string result(str.size(),'\0');
38
+ std::transform(str.begin(), str.end(), result.begin(),
39
+ [](char ch) { return isupper(ch) ? tolower(ch) :
40
+ (islower(ch) ? toupper(ch) : ch); });
41
+ return result;
42
+ }
43
+
44
+ int main() {
45
+ std::string line;
46
+ while ( std::getline(std::cin, line) && line.size() != 0 ) {
47
+ std::cout << '[' << line << "] -> [" << change(line) << "]\n";
48
+ }
49
+ }
27
50
  ```