※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 26560번 문제인 Period이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/26560 

 

26560번: Periods

Eric gets distracted so sometimes he forgets to put periods at the end of his sentences. To help him out, you are to put a period at the end of his sentences if the period is not already present.

www.acmicpc.net

주어지는 각 문장을 getline으로 줄 단위로 읽은 뒤, 해당 문장이 '.'으로 끝나는지를 확인해 문제를 해결하자.

 

주어진 문자열의 마지막 문자는 back()을 이용해 쉽게 접근할 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;

int T;
string s;

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

	getline(cin, s);
	T = stoi(s);
	while (T--) {
		getline(cin, s);

		if (s.back() != '.') s += ".";
		cout << s << '\n';
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 26502 // C++] Decoder  (0) 2022.12.21
[BOJ 26536 // C++] Cowspeak  (0) 2022.12.21
[BOJ 26547 // C++] Square  (0) 2022.12.21
[BOJ 26510 // C++] V for Vendetta  (0) 2022.12.21
[BOJ 22421 // C++] Koto Municipal Subway  (0) 2022.12.21

+ Recent posts