작성일 :

문제 링크

21964번 - 선린인터넷고등학교 교가

설명

문자열의 마지막 5글자를 출력하는 문제입니다.


접근법

문자열 끝에서 5글자만 잘라 출력합니다.


Code

C#

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

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    var s = Console.ReadLine()!;
    Console.WriteLine(s.Substring(n - 5, 5));
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;

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

  int n; 
  if (!(cin >> n)) return 0;
  string s; 
  cin >> s;
  cout << s.substr(n - 5, 5) << "\n";

  return 0;
}