※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 5340번 문제인 Secret Location이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/5340
5340번: Secret Location
Someone is waiting at a secret location and has sent a text message with the coordinates of their location. The message contains the latitude and longitude coordinates in degrees, minutes, and seconds. Of course, the message is encoded so you must write a
www.acmicpc.net
각 줄에 주어지는 문장을 구성하는 문자의 개수를 세 위도와 경도의 각 항의 값을 구하고 문제를 해결하자.
주어진 예제의 네번째 줄을 관찰하는 것으로 뒤에 따라오는 공백의 경우 문자의 개수에 포함시키지 않음을 알 수 있다. 이에 유의하여 구현하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << "Latitude ";
getline(cin, s);
while (!s.empty() && s.back() == ' ') s.pop_back();
cout << s.length() << ':';
getline(cin, s);
while (!s.empty() && s.back() == ' ') s.pop_back();
cout << s.length() << ':';
getline(cin, s);
while (!s.empty() && s.back() == ' ') s.pop_back();
cout << s.length() << '\n';
cout << "Longitude ";
getline(cin, s);
while (!s.empty() && s.back() == ' ') s.pop_back();
cout << s.length() << ':';
getline(cin, s);
while (!s.empty() && s.back() == ' ') s.pop_back();
cout << s.length() << ':';
getline(cin, s);
while (!s.empty() && s.back() == ' ') s.pop_back();
cout << s.length() << '\n';
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 4327 // C++] Combination Lock (0) | 2022.12.22 |
---|---|
[BOJ 26587 // C++] Reverse (0) | 2022.12.22 |
[BOJ 5342 // C++] Billing (0) | 2022.12.22 |
[BOJ 5292 // C++] Counting Swann's Coins (0) | 2022.12.22 |
[BOJ 15179 // C++] Golf Croquet (0) | 2022.12.22 |