※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26500번 문제인 Absolutely이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26500
26500번: Absolutely
The first line contains a single positive integer, n, indicating the number of data sets. Each data set is on a separate line and contains two values on the number line, separated by a single space.
www.acmicpc.net
각 테스트케이스마다 주어지는 두 수의 차를 출력해 문제를 해결하자.
각 수의 절댓값은 abs 함수를 이용해 쉽게 구해낼 수 있다.
fixed와 cout.precision을 이용해 출력 자릿수를 조절하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long double ld;
int T;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed;
cout.precision(1);
cin >> T;
while (T--) {
ld x, y; cin >> x >> y;
cout << abs(x - y) << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26574 // C++] Copier (0) | 2022.12.19 |
---|---|
[BOJ 5300 // C++] Fill the Rowboats! (0) | 2022.12.19 |
[BOJ 26575 // C++] Pups (0) | 2022.12.19 |
[BOJ 26530 // C++] Shipping (0) | 2022.12.19 |
[BOJ 26489 // C++] Gum Gum for Jay Jay (0) | 2022.12.18 |