[백준 28373] Eszett (C#, C++) - soo:bak
작성일 :
문제 링크
설명
대문자 단어가 주어질 때, 원래 소문자였을 수 있는 모든 경우를 출력하는 문제입니다. SS는 원래 ss였거나 ß였을 수 있으며, ß는 B로 표기합니다.
접근법
먼저 전체를 소문자로 변환해 출력합니다.
ss가 있으면 이를 B로 대체한 경우도 출력합니다. sss가 있으면 앞쪽 ss와 뒤쪽 ss를 각각 B로 바꾼 두 경우를 출력합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
class Program {
static void Main() {
var s = Console.ReadLine()!.ToLower();
Console.WriteLine(s);
var pos = s.IndexOf("ss");
if (pos == -1) return;
var posSSS = s.IndexOf("sss");
if (posSSS != -1) {
var lastSS = s.LastIndexOf("ss");
Console.WriteLine(s[..lastSS] + "B" + s[(lastSS + 2)..]);
Console.WriteLine(s[..pos] + "B" + s[(pos + 2)..]);
} else Console.WriteLine(s[..pos] + "B" + s[(pos + 2)..]);
}
}
C++
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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s; cin >> s;
for (char& c : s)
c = tolower(c);
cout << s << "\n";
size_t pos = s.find("ss");
if (pos == string::npos) return 0;
if (s.find("sss") != string::npos) {
size_t lastSS = s.rfind("ss");
cout << s.substr(0, lastSS) << 'B' << s.substr(lastSS + 2) << "\n";
cout << s.substr(0, pos) << 'B' << s.substr(pos + 2) << "\n";
} else cout << s.substr(0, pos) << 'B' << s.substr(pos + 2) << "\n";
return 0;
}