Notice
Recent Posts
Recent Comments
Link
«   2025/10   »
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
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

코딩로그

[백준/BOJ/C++] 9086번 문자열 본문

YJ/C++

[백준/BOJ/C++] 9086번 문자열

Team DAON 2021. 10. 18. 16:44

[문제]

문자열을 입력으로 주면 문자열의 첫 글자와 마지막 글자를 출력하는 프로그램을 작성하시오.

 

[입력]

입력의 첫 줄에는 테스트 케이스의 개수 T(1 ≤ T ≤ 10)가 주어진다. 각 테스트 케이스는 한 줄에 하나의 문자열이 주어진다. 문자열은 알파벳 A~Z 대문자로 이루어지며 알파벳 사이에 공백은 없으며 문자열의 길이는 1000보다 작다.

 

[출력]

각 테스트 케이스에 대해서 주어진 문자열의 첫 글자와 마지막 글자를 연속하여 출력한다.

 

[Source Code]

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> vector;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		string result;
		result = s[0];
		result += s[s.length()-1];

		vector.push_back(result);
	}

	for(int i = 0; i < n; i++){
		cout << vector[i] << "\n";
	}
}

[결과 화면]