대소문자 뒤바꾸기
한 줄의 문자열이 주어진다.
영어 대문자는 소문자로, 영어 소문자는 대문자로 바꾸고, 그 밖의 문자(숫자·기호·빈칸)는 그대로 두어 한 줄로 출력하라.
- 입력
- 길이 1 ~ 200, 아스키 출력 가능 문자(코드 32~126)만.
빈칸이 들어 있을 수 있다 - 출력
- 바꾼 문자열 한 줄
Hello, World 2026!
hELLO, wORLD 2026!
한 줄의 문자열이 주어진다.
영어 대문자는 소문자로, 영어 소문자는 대문자로 바꾸고, 그 밖의 문자(숫자·기호·빈칸)는 그대로 두어 한 줄로 출력하라.
Hello, World 2026!
hELLO, wORLD 2026!
실행하면 이 줄들이 차례로 input()·표준 입력으로 들어가요(실행 중에 묻지 않아요).
$ 준비됐어요
코드를 입력해 풀려면 PC에서 열어 주세요. 모바일에서는 문제와 풀이를 볼 수 있어요.
한 번에 해 주는 함수는 Python s.swapcase()뿐이에요.
나머지는 한 글자씩 돌며 묻고 바꿔요: Java Character.isUpperCase/toLowerCase, C# char.IsUpper/char.ToLower, C·C++ <ctype.h>의 isupper/tolower(인자는 unsigned char로), JS·TS는 c >= "A" && c <= "Z"로 묻고 toLowerCase(), 크레이콘은 c != c.소문자로변환()면 대문자예요.
함정: 아스키에서 대소문자가 32 차이라고 모든 문자에 c ^ 32를 하면 숫자·기호·빈칸까지 망가져요.
글자인지 먼저 물어야 해요.
s = input()print(s.swapcase())const s = require("fs").readFileSync(0, "utf8").split("\n")[0].replace(/\r$/, "");let out = "";for (const c of s) { if (c >= "A" && c <= "Z") out += c.toLowerCase(); else if (c >= "a" && c <= "z") out += c.toUpperCase(); else out += c;}console.log(out);import { readFileSync } from "node:fs";const s: string = readFileSync(0, "utf8").split("\n")[0].replace(/\r$/, "");let out = "";for (const c of s) { if (c >= "A" && c <= "Z") out += c.toLowerCase(); else if (c >= "a" && c <= "z") out += c.toUpperCase(); else out += c;}console.log(out);import java.io.BufferedReader;import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); StringBuilder out = new StringBuilder(); for (char c : s.toCharArray()) { if (Character.isUpperCase(c)) out.append(Character.toLowerCase(c)); else if (Character.isLowerCase(c)) out.append(Character.toUpperCase(c)); else out.append(c); } System.out.println(out); }}using System;using System.Text; class Program{ static void Main() { string s = Console.ReadLine(); var sb = new StringBuilder(); foreach (char c in s) { if (char.IsUpper(c)) sb.Append(char.ToLower(c)); else if (char.IsLower(c)) sb.Append(char.ToUpper(c)); else sb.Append(c); } Console.WriteLine(sb.ToString()); }}#include <cctype>#include <iostream>#include <string> int main() { std::string s; std::getline(std::cin, s); if (!s.empty() && s.back() == '\r') s.pop_back(); for (char& c : s) { unsigned char u = static_cast<unsigned char>(c); if (std::isupper(u)) c = static_cast<char>(std::tolower(u)); else if (std::islower(u)) c = static_cast<char>(std::toupper(u)); } std::cout << s << "\n";}#include <ctype.h>#include <stdio.h>#include <string.h> int main(void) { char s[256]; if (!fgets(s, sizeof s, stdin)) return 0; s[strcspn(s, "\r\n")] = '\0'; for (int i = 0; s[i]; i++) { unsigned char c = (unsigned char)s[i]; if (isupper(c)) s[i] = (char)tolower(c); else if (islower(c)) s[i] = (char)toupper(c); } puts(s); return 0;}s = 콘솔.줄읽기();out = "";각각 (c 에서 s){ 만약 (c != c.소문자로변환()) { out = out + c.소문자로변환(); } 아니면 만약 (c != c.대문자로변환()) { out = out + c.대문자로변환(); } 아니면 { out = out + c; }}콘솔.쓰기(out);