작성일 :

문제 링크

5362번 - Garbled Message

설명

문장에서 iiing을 모두 th로 바꿔 원문을 복원하는 문제입니다.


접근법

입력을 한 줄씩 읽어 iiing을 th로 치환한 결과를 그대로 출력합니다.

이후 입력이 끝날 때까지 반복합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
using System;

class Program {
  static void Main() {
    string? line;
    while ((line = Console.ReadLine()) != null) {
      Console.WriteLine(line.Replace("iiing", "th"));
    }
  }
}

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
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string line;
  while (getline(cin, line)) {
    string res;
    for (int i = 0; i < (int)line.size(); ) {
      if (i + 5 <= (int)line.size() && line.substr(i, 5) == "iiing") {
        res += "th";
        i += 5;
      } else {
        res.push_back(line[i]);
        i++;
      }
    }
    cout << res << "\n";
  }

  return 0;
}